[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3273) One-to-Many relationship not working with custom Loader

David Balažic (JIRA) noreply at atlassian.com
Wed Jan 5 18:12:06 EST 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3273?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=39498#action_39498 ] 

David Balažic commented on HHH-3273:
------------------------------------

Still in 3.6.0.Final it seems.

> One-to-Many relationship not working with custom Loader 
> --------------------------------------------------------
>
>                 Key: HHH-3273
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3273
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.2.1, 3.2.2, 3.2.3, 3.2.4, 3.2.5, 3.2.6, 3.3.1, 3.5.5
>         Environment: hibernate-3.2.6.jar
>            Reporter: Darren Hicks
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> Within the context of a One-to-Many relationship, NamedQueryCollectionInitializer .initialize() never actually populates the PersistantBag on the parent after it calls query.setCollectionKey( key ).setFlushMode( FlushMode.MANUAL ).list() to retrieve the children.
> This is documented in the forums here: http://forums.hibernate.org/viewtopic.php?t=986428
> Additionally, the poster has a fix posted which may solve the problem, or at least lay out the groundwork for a solution.  Here is the proposed implementation of NamedQueryCollectionInitializer.initialize():
> public void initialize(Serializable key, SessionImplementor session)
>          throws HibernateException {
>       if (log.isDebugEnabled()) {
>          log.debug("initializing collection: " + persister.getRole()
>                + " using named query: " + queryName);
>       }
>       // TODO: is there a more elegant way than downcasting?
>       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());
>       }
>       List list = query.setCollectionKey(key).setFlushMode(FlushMode.MANUAL)
>             .list();
>       // Uh, how 'bout we save the collection for later retrieval?
>       CollectionKey collectionKey = new CollectionKey(persister, key, session
>             .getEntityMode());
>       for (Object object : session.getPersistenceContext()
>             .getCollectionsByKey().keySet()) {
>          if (collectionKey.equals(object)) {
>             PersistentCollection persistentCollection = session
>                   .getPersistenceContext().getCollection(collectionKey);
>             Serializable[] serializables = new Serializable[list.size()];
>             for (int i = 0; i < list.size(); i++) {
>                serializables[i] = persister.getElementType().disassemble(
>                      list.get(i), session,
>                      persistentCollection.getOwner());
>             }
>             persistentCollection.initializeFromCache(persister,
>                   serializables, persistentCollection.getOwner());
>             persistentCollection.setSnapshot(key, persistentCollection
>                   .getRole(), serializables);
>             persistentCollection.afterInitialize();
>             session.getPersistenceContext().getCollectionEntry(
>                   persistentCollection).postInitialize(
>                   persistentCollection);
>          }
>       }
>    }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       



More information about the hibernate-issues mailing list