This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

LazyInitializationException

 
vijaya sharma
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We just migrated from hibernate2 to hibernate3, and everything seems to work just fine except this error which i get only when i try to load some object. Also I don't think it's significant in this context but we are using spring along with hibernate. Now the error seems to come only when I try to insert, or update.

Full stack trace is here:

org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:56)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:98)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:158)
at some.hibernate.UserAccount$$EnhancerByCGLIB$$80039dd0_2.getUserAccountName(<generated>
at com.some.dao.someUserPrefReadWriteHibernate.InsertMBDefault(someUserPrefReadWriteHibernate.java:160)
at com.some.dao.someCSRDaoTest.testPAsomeCSRDao(someCSRDaoTest.java:148)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:228)
at junit.framework.TestSuite.run(TestSuite.java:223)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


ANY VIEW ON THIS WOULD BE GREATLY APPRECIATED,

Thanks,
Vijay.
 
Prashanth Talapala
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like the hiberante Session is closed and then you want to insert / update the object. This will cause an error when it comes to lazy initialised elements of the object like Set, Map etc. Try to refresh the object from the db and then save it.

-Prashanth.
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One point to note is that in Hibernate2 the lazy attribute defaulted to "false" whereas in Hibernate3 it defaults to "true". So you might need to explicitly set lazy="false" wherever you dont need lazy behaviour
[ March 20, 2006: Message edited by: jaikiran pai ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic