0 Replies Latest reply on Jul 24, 2008 5:27 AM by Ale Fred

    @NamedNativeQuery and collection loading

    Ale Fred Newbie

      I'm using a parametrized named native query to initialize a collection property.
      Everything seems to work fine except for the fact that hibernate passes just one parameter to the query which is the bean's id.

      Looking at the hibernate's NamedQueryCollectionInitializer sources i found that :

      public void initialize(Serializable key, SessionImplementor session)
       throws HibernateException {
       if (log.isDebugEnabled())
       log.debug("initializing collection: " + persister.getRole()
       + " using named query: " + queryName);
       AbstractQueryImpl query = (AbstractQueryImpl) session
       .getNamedSQLQuery(queryName);
       if (query.getNamedParameters().length > 0)
       query.setParameter(query.getNamedParameters()[0], key, persister
       .getKeyType());
       else
       query.setParameter(0, key, persister.getKeyType());
       query.setCollectionKey(key).setFlushMode(FlushMode.MANUAL).list();
       }


      which confirms that just the first parameter is applied, referring its type as the key one.

      Is there a way to pass more than one parameter?

      Thanks.