Community

Lazy loading problem: ERROR [LazyInitializationException]

created by Gabriel Muench in EJB 3.0 - View the full discussion

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

Start a new discussion in EJB 3.0 at Community