[jboss-user] [EJB 3.0] - Lazy loading problem: ERROR [LazyInitializationException]
Gabriel Muench
do-not-reply at jboss.com
Mon Mar 22 12:34:46 EDT 2010
Gabriel Muench [http://community.jboss.org/people/Fuchs] created the discussion
"Lazy loading problem: ERROR [LazyInitializationException]"
To view the discussion, visit: http://community.jboss.org/message/533329#533329
--------------------------------------------------------------
Hello, i have a problem with LazyInitialization.
Here is the error message:
15:25:14,950 ERROR [LazyInitializationException] failed to lazily initialize a collection of role: de.database.entities.Customer.powMeters, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: de.database.entities.Customer.powMeters, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
...
15:25:14,955 ERROR [LazyInitializationException] failed to lazily initialize a collection of role: de.database.entities.Customer.powMeters, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: de.database.entities.Customer.powMeters, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
...
15:25:14,958 ERROR [STDERR] org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: de.database.entities.Customer.powMeters, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
...
15:25:14,959 ERROR [STDERR] rtal.portlet.aspects.portlet.PortletSessionSynchronizationInterceptor.invoke(PortletSessionSynchronizationInterceptor.java:82)
at org.jboss.portal.portlet.PortletInvokerInterceptor.invoke(PortletInvokerInterceptor.java:82)
...
15:25:14,960 ERROR [STDERR] ptor.invoke(ControllerInterceptor.java:40)
at org.jboss.portal.common.invocation.Invocation.invokeNext(Invocation.java:115)
...
15:25:14,960 ERROR [STDERR] ts.tx.TxInterceptor$RequiresNew.invoke(TxInterceptor.java:253)
at org.jboss.portal.core.aspects.server.TransactionInterceptor$invoke_N5143606530999904530.invokeNext(TransactionInterceptor$invoke_N5143606530999904530.java)
...
About the environment:
I use Hibernate as persistence provider and
EJB 3 Annotations + Java 5 to map a MySQL database.
The mapping is intergrated into the JBoss Portal 2.7.2 server.
My JSF 1.1.14 + Facelets and Richfaces 3.3.1 portlet with PortletBridge 1.0.0 use the persistence mapping in this way:
ICustomerHome customers = (ICustomerHome) context.lookup("CustomerHome/local");
customer = customers.findByJbossUser(username);
powIds = new ArrayList<Integer>();
powMeterList = customer.getPowMeters();
This is what i have done to avoid the problem with lazy loading, till now:
Customer instance = entityManager.find(Customer.class, id);
instance.getPowMeters().size();
But i think this solution is not the right way. There must be a fault in "Transaction",
because the same should be done with EAGER loading.
If i use EAGER FetchType instead of LAZY the problem will not be solved.
@OneToMany(fetch = FetchType.EAGER, mappedBy = "customer")
public Set<PowMeter> getPowMeters() {
return this.powMeters;
}
Can anyone help me, please?
Cheers!
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/533329#533329]
Start a new discussion in EJB 3.0 at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20100322/64f58e4a/attachment.html
More information about the jboss-user
mailing list