jboss-as-7.1.1.Final Lazy-Loading problem
mortimor Jun 12, 2012 8:26 AMHello,
i have switched my project from "jboss-as-web-7.0.2.Final" to "jboss-as-7.1.1.Final".
Now Lazy-Loading seems not to function.
My Bean:
... @OneToMany(mappedBy="mbMenueitem") @OrderBy(value="position asc") private Set<MbMenueitem> mbMenueitems;
My Controller
@Model public class MenueItemProducer2 implements Serializable { @Inject private EntityManager em; ... List<MbMenueitem>tmpMenue =em.createQuery(criteria).getResultList(); if(tmpMenue.size()>0){ tmpItem=tmpMenue.get(0); Set<MbMenueitem> orderLines= tmpItem.getMbMenueitems(); System.out.println("Size: "+orderLines.size()); <-- stops here }
ErrorMessage
Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: org.jboss.as.quickstarts.kitchensink.model.MbMenueitem.mbMenueitems, no session or session was closed at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:393) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:385) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.collection.internal.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:125) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.collection.internal.PersistentSet.size(PersistentSet.java:156) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.jboss.as.quickstarts.kitchensink.data.MenueItemProducer2.findMenueItem(MenueItemProducer2.java:253) [classes:] at org.jboss.as.quickstarts.kitchensink.data.MenueItemProducer2.fillItems2(MenueItemProducer2.java:123) [classes:] at org.jboss.as.quickstarts.kitchensink.data.MenueItemProducer2.refreshMenue(MenueItemProducer2.java:86) [classes:]
I have tried this, but it did not solve the problem:
@PersistenceContext(type=PersistenceContextType.EXTENDED) private EntityManager em;