[jboss-jira] [JBoss JIRA] (HIBERNATE-138) [HHH-7629] Initialize PersistentCollection with fetchType LAZY returns NPE

Brett Meyer (JIRA) jira-events at lists.jboss.org
Mon Sep 24 13:27:34 EDT 2012


    [ https://issues.jboss.org/browse/HIBERNATE-138?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12721106#comment-12721106 ] 

Brett Meyer commented on HIBERNATE-138:
---------------------------------------

[~rimolive], I'm a little confused by the code example.  Is 'entity' the collection, or aProperty's parent entity?

Normally, I'd expect something like this:

Foo entity = session.get(Foo.class, id);
Hibernate.initialize(entity.getAProperty());
or
((PersistentCollection) entity.getAProperty()).forceInitialization();

Can the customer give any more code examples?  A full test-case would be really helpful.  Thanks!
                
> [HHH-7629] Initialize PersistentCollection with fetchType LAZY returns NPE 
> ---------------------------------------------------------------------------
>
>                 Key: HIBERNATE-138
>                 URL: https://issues.jboss.org/browse/HIBERNATE-138
>             Project: Hibernate Integration
>          Issue Type: Bug
>            Reporter: Ricardo Martinelli Oliveira
>            Assignee: Brett Meyer
>
> @JoinTable(name = "JOIN_TABLE", joinColumns = { @JoinColumn(name = "JOIN_TABLE_ID", referencedColumnName = "ID") }, inverseJoinColumns = { @JoinColumn(name = "ENTITY_ID", referencedColumnName = "ID") })
> @ManyToMany(fetch = FetchType.LAZY)
> private Set<JoinTable> aProperty;
> When fetching this entity, and after initialize, I get all the valid attribute values but the aProperty is defined as PersistenceCollection.
> This collection is not intialized yet. When I initialize this collection as follow:
> (PersistentCollection) entity).forceInitialization();
> Or
> Hibernate.initialize(entity);
> I got NullPointerException:
> Caused by: java.lang.NullPointerException
> at org.hibernate.engine.internal.StatefulPersistenceContext.getLoadedCollectionOwnerOrNull(StatefulPersistenceContext.java:790)
> at org.hibernate.event.spi.AbstractCollectionEvent.getLoadedOwnerOrNull(AbstractCollectionEvent.java:75)
> at org.hibernate.event.spi.InitializeCollectionEvent.<init>(InitializeCollectionEvent.java:36)
> at org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:1803)
> at org.hibernate.collection.internal.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:489)
> at org.hibernate.Hibernate.initialize(Hibernate.java:77)
> When I check source code of class org.hibernate.engine.internal.StatefulPersistenceContext.getLoadedCollectionOwnerOrNull(StatefulPersistenceContext.java:790)
> CollectionEntry ce = getCollectionEntry( collection );
> 790 if ( ce.getLoadedPersister() == null ) { 791 return null; // early exit... 792 }
> Looks like the CollectionEntry ce is null. This collection entry is fetched from collectionEntries.get(coll);
> // Identity map of CollectionEntry instances, by the collection wrapper
> 121 private IdentityMap<PersistentCollection, CollectionEntry> collectionEntries;
> I checked Jboss docs, it mentioned the way to initilialize the collection is as I have done above.
> http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/performance.html#performance-fetching-initialization

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the jboss-jira mailing list