I am using Jboss 5.1 version with hibernate/JPA to communicate with DB.
In one of my module I am facing Lazy Load exception. Below is the trace for that.
2013-06-05 06:19:20,221 ERROR [org.hibernate.LazyInitializationException] (http-127.0.0.1-8080-1) could not initialize proxy - no Session
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
This is happening only when I am trying to load some huge set of data ( approx 100000 no of record which took around 30 min to load from DB) from DB and iterating the list of entities to access some data (ManyToOne relationship which is lazily loaded initially) out of entity object. I am not getting this error when I am trying for smaller set of record (10000 to 50000) which is fetched in very less time.
I tried reconnect the Entitymanager before access the attribute of entity object in the following way. But there is no luck still.
Is there anyone who face similar issue or have any idea/clue about the issue, Kindly let me know. Any kind of help is appreciated.
Just a random thought.. I believe you might be doing all this data fetch inside a transaction. In that case, it's working looking at it from a transaction time-out perspective as well. By default, the Transactions have a 5min timeout values. You can try increasing the timeout values and verify your large data loads.
( SCBCD 5, CCENT, SCJP 5 )
Joined: Oct 13, 2010
Thanks for your reply.
I have alredy tried setting "transactionTimeout" value to "999999" in transaction-jboss-bean.xml also. But it still didn't work out.
And one more thing, when I am trying to load the lazy data in the Selector class(where I am getting entire entity list from DB) by iterating the entity list, I am able to load the lazy data. But when I am coming out of the selector class and going to a builder class ( used for building TO object out of entity object) with the entity list, there I am getting LazyLoadException.
Is it something to do with Bean life of EJB ? Please suggest.
In that case, the only reason i can think of is - The Selector class is inside the scope of transaction. So, when you are trying to lazily fetch the data, it would work fine. But, when you go to the builder class, the transaction would scope would have ended, the hibernate session gets closed. So, if you now try accessing the data which is supposed to be fetched lazily, it will not work.
I am not much aware of hibernate session internals. So, I cannot provide more inputs here.
subject: LazyLoadException on hibernate/JPA entity manager for huge volume of data