GeeCON Prague 2014*
The moose likes Object Relational Mapping and the fly likes LazyInitializationException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "LazyInitializationException" Watch "LazyInitializationException" New topic
Author

LazyInitializationException

vijaya sharma
Greenhorn

Joined: Dec 30, 2003
Posts: 15
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.


only thing constant is change
Prashanth Talapala
Greenhorn

Joined: Apr 03, 2005
Posts: 9
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

Joined: Jul 20, 2005
Posts: 10146
    
165

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 ]

[My Blog] [JavaRanch Journal]
 
GeeCON Prague 2014
 
subject: LazyInitializationException