-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: How do I fix org.hibernate.LazyInitializationException
PostPosted: Wed Jul 26, 2006 12:46 pm 
Newbie

Joined: Wed Jul 26, 2006 11:06 am
Posts: 11
I have a simple query that retrieves an entity from the database. Within that object I call a method to get a collection of different entitys.

Like so...
Code:
List<Object> l = entity.getCollection();


From searching google and reading posts I understand that I have a session issue and could fix the problem by using and EAGER strategy. However, I cannot get the eager to work either. I get the same error regardless of what I do.

I'm running the lastest version of JBoss AS and Seam.

Here's the actual code.
Code:

  @DataModel
  private Set<RemittanceItemEntity> remitItems;

    remitItems = packages.getSelectedClosedPackage().getRemittanceItems();   

-----------------

Here is the entity bean method with annotations

   @OneToMany(mappedBy="remittancePackage")
   public Set<RemittanceItemEntity> getRemittanceItems() {
      return remittanceItems;
   }




Here's the exception...although I'm sure you guys have seent this one before...
Code:
Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.vicor.DistributedCapture.ejb.PackageEntity.remittanceItems, no session or session was closed
   at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
   at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
   at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:97)
   at org.hibernate.collection.PersistentSet.size(PersistentSet.java:114)
   at java.util.ArrayList.<init>(ArrayList.java:133)
   at org.jboss.seam.jsf.SetDataModel.setWrappedData(SetDataModel.java:96)
   at org.jboss.seam.jsf.SetDataModel.<init>(SetDataModel.java:33)
   at org.jboss.seam.databinding.DataModelBinder.wrap(DataModelBinder.java:48)
   at org.jboss.seam.databinding.DataModelBinder.wrap(DataModelBinder.java:19)
   at org.jboss.seam.Component.outjectDataModelList(Component.java:980)
   at org.jboss.seam.Component.outjectDataModels(Component.java:937)
   at org.jboss.seam.Component.outject(Component.java:857)
   at org.jboss.seam.interceptors.BijectionInterceptor.bijectTargetComponent(BijectionInterceptor.java:41)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
   at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:90)
   at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
   at org.jboss.seam.interceptors.ConversationInterceptor.endOrBeginLongRunningConversation(ConversationInterceptor.java:82)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
   at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:90)
   at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
   at org.jboss.seam.interceptors.BusinessProcessInterceptor.manageBusinessProcessContext(BusinessProcessInterceptor.java:60)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
   at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:90)
   at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
   at org.jboss.seam.interceptors.RemoveInterceptor.removeIfNecessary(RemoveInterceptor.java:39)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
   at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:90)
   at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
   at org.jboss.seam.ejb.SeamInterceptor.aroundInvokeInContexts(SeamInterceptor.java:73)
   at org.jboss.seam.ejb.SeamInterceptor.aroundInvoke(SeamInterceptor.java:45)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
   at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
   at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:57)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
   at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
   at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
   at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
   ... 45 more


Thanks.
Eric Ray


Top
 Profile  
 
 Post subject: EAGER is working
PostPosted: Wed Jul 26, 2006 12:54 pm 
Newbie

Joined: Wed Jul 26, 2006 11:06 am
Posts: 11
Okay, I figured out where to annotate for EAGER. However, I still need to better understand lazy initialization. Advice and suggestions greatly appreciated.

Thanks.
Eric Ray


Top
 Profile  
 
 Post subject: the answer
PostPosted: Wed Jul 26, 2006 1:48 pm 
Newbie

Joined: Wed Jul 26, 2006 11:06 am
Posts: 11
use the merge method on the entity manager to "merge the state of the given entity into the current persistence context."

In my situation I replaced this...

Code:
remitItems = packages.getSelectedClosedPackage().getRemittanceItems(); 

with this
Code:
    PackageEntity pe = em.merge(packages.getSelectedOpenPackage());
    remitItems = pe.getRemittanceItems(); 


Now the PackageEntity object is brought into this persistence context. At least that what looks like what is happening. I'm new to this stuff so I could be wrong.

Thanks.
Eric Ray


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.