I have a MainObject class, which has a many-to-one mapping relationship to the ChildObject class, I've also created a property mapping for the ChildObject's ID in the MainObject besides the reference, so as you can see below the "ChildObject_ID" column is mapped twice, once for the reference and once for the ID. This mapping has been working fine.
At some point I ran into the following exception (see below) - it seems Hibernate is trying to do a lazy load when I call MainObject.getChildObjectID, even this ID is part of the MainObject's own property. I thought lazy loading is involved only when a referenced object is being loaded? Am I wrong or there's something else going on?
Thanks!
Ken
Hibernate version: 3.2.0GA
Mapping documents:
Quote:
<many-to-one name="objects" access="field" class="com.company.model.ChildObject" fetch="join" insert="false" update="false">
<column name="ChildObject_ID" />
</many-to-one>
<property name="childObjectID" type="java.lang.Long">
<column name="ChildObject_ID"/>
</property>
Code between sessionFactory.openSession() and session.close():Using Spring transaction manager so I don't deal with sessions directly.
Full stack trace of any exception that occurs:Quote:
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:60)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:172)
at com.company.model.MainObject$$EnhancerByCGLIB$$8c501d04.getChildObjectID(<generated>)
......
at java.util.TimerThread.mainLoop(Timer.java:432)
at java.util.TimerThread.run(Timer.java:382)
Name and version of the database you are using:MS SQL server 2003.
The generated SQL (show_sql=true):Debug level Hibernate log excerpt:Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.htmlQuote: