[
https://jira.jboss.org/jira/browse/JBAS-5474?page=com.atlassian.jira.plug...
]
arjan tijms commented on JBAS-5474:
-----------------------------------
Same issue and apparently still no resolution.
When accessing the association in the setter method, the following exception is thrown:
12:14:11,327 ERROR [LazyInitializationException] failed to lazily initialize a collection,
no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no
session or session was closed
at
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:380)
at
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:372)
at
org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:119)
at org.hibernate.collection.PersistentSet.size(PersistentSet.java:162)
at java.util.LinkedHashSet.<init>(LinkedHashSet.java:151)
While accessing the association in the @PostLoad annotated method throws a different
exception:
org.hibernate.LazyInitializationException: illegal access to loading collection
at
org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:363)
at
org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108)
at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:186)
In the last case, Hibernate explicitly checks whether the collection is still
'initializing', thus it's not related to any persistence context being closed.
I'm not sure why the first exception does say that. Is that a bug in the exception
that is thrown due to this bug?
The code that throws the exception when accessing the association in the @PostLoad method
is the following:
/**
* Initialize the collection, if possible, wrapping any exceptions
* in a runtime exception
* @param writing currently obsolete
* @throws LazyInitializationException if we cannot initialize
*/
protected final void initialize(boolean writing) {
if (!initialized) {
if (initializing) {
throw new LazyInitializationException("illegal access to loading
collection");
}
throwLazyInitializationExceptionIfNotConnected();
session.initializeCollection(this, writing);
}
}
@PostLoad -> LazyInitializationException: illegal access to
loading collection ond a @OneToMany with FetchType.EAGER
--------------------------------------------------------------------------------------------------------------------
Key: JBAS-5474
URL:
https://jira.jboss.org/jira/browse/JBAS-5474
Project: JBoss Application Server
Issue Type: Bug
Security Level: Public(Everyone can see)
Components: EJB3
Affects Versions: JBossAS-4.2.2.GA
Environment: Win XP SP2, Java 1.5.0_15-b04
Reporter: Stefan Lindner
Assignee: Emmanuel Bernard
Attachments: Child.java, Parent.java, PostLoadTest.java
I have a bean with a @OneToMany relation mapping like
private List<TherapieeinheitBean> therapieeinheiten;
@OneToMany(
cascade = {CascadeType.REFRESH},
fetch = FetchType.EAGER,
mappedBy="therapiekatalog"
)
with FetchType.EAGER and a simnple @PostLoad like
@PostLoad
public void postLoad() {
System.out.println("!!!!!!!!!! postLoad !!!!!!!!!!");
System.out.print("size: " + therapieeinheiten.size());
}
When an entity of this bean is loaded JBoss trows
org.hibernate.LazyInitializationException: illegal access to loading collection
at
org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:341)
at
org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:249)
at
de.visiodesk.therapiekatalog.TherapiekatalogBean.postLoad(TherapiekatalogBean.java:170)
.
.
.
and prints the messages
WARN [LoadContexts] fail-safe cleanup (collections) :
org.hibernate.engine.loading.CollectionLoadContext@2c8ce9<rs=Ingres-ResultSet[18523]>
WARN [CollectionLoadContext] On CollectionLoadContext#cleanup,
localLoadingCollectionKeys contained [206] entries
afterwards. The PostLoad method should be called after the data was completely loaded. Is
there a workaround for this Problem? I found some other ressources on the net where peole
had the same problem, but I saw no resolution, no hint, no workaround.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira