PDA

View Full Version : org.hibernate.LazyInitializationException: even tho .hbm.xml has lazy="false"



zagor
Sep 6th, 2007, 12:21 PM
I am getting the following error:

org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initia lize(AbstractLazyInitializer.java:53)
at org.hibernate.proxy.AbstractLazyInitializer.getImp lementation(AbstractLazyInitializer.java:80)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept (CGLIBLazyInitializer.java:133)
...

Even tho my .hbm.xml file has the lazy=false:

<many-to-one name="product" column="PRODUCT_MODEL_ID" class="com.xxx.xxx.dataobjects.ProductImpl" lazy="false" insert="false" update="false" cascade="all"/>

It works fine when the code runs within JBoss, but when running the code from TestNG it fails.

Anyone seen this before?

Thanks

karldmoore
Sep 6th, 2007, 01:22 PM
Your running the same code in both places? I'd start by having a look at the DEBUG logs.

zagor
Sep 12th, 2007, 02:06 PM
So I finally got my code to work. I rebuilt my classpath in Eclipse from scratch and this got rid of the lazy fetch Exception. Not sure if I was grabbing a previous war instead of the .class files. Hopefully this will help someone. Thanks for the reply Karl.