gavin wrote:
Isn't it amazing how many "bugs" are fixed when you actually read documentation for things you are using:
http://www.hibernate.org/hib_docs/v3/re ... -manytooneQuote:
lazy (optional - defaults to proxy): By default, single point associations are proxied. lazy="true" specifies that the property should be fetched lazily when the instance variable is first accessed (requires build-time bytecode instrumentation).
We have renamed this option in 3.1 because so many users are allergic to that pesky documentation stuff we put so much time and effort into.
My Question still remains.
I understood the part that as and when i access the instance variable first is when lazy="true" works.
this is my scenario.
Net.hbm.xml file.
<hibernate-mapping>
<class name="com.hibernate.example.pos.Net" table="NETS">
.....
<!-- corresponds to bidirecional one-to-many -->
<set name="imdscannedconfig" lazy="true"
inverse="true"
cascade="save-update">
<key column="NET_ID"></key>
<one-to-many class="com.hibernate.example.pos.Imdscannedconfig"/>
</set>
</class>
</hibernate-mapping>
Imdscannedconfig.hbm.xml
<hibernate-mapping>
<class name="com.hibernate.example.pos.Imdscannedconfig" table="IMDSCANNED">
....
<many-to-one name="net" lazy="true"
column="NET_ID"
class="com.hibernate.example.pos.Net"
not-null="true"/>
...
</class>
</hibernate-mapping>
When i do a
session.load(Net.class, id).
The lazy="true" parameter on the many-to-one tag works and doesn't select the Imdscannedconfig object till i first access the instance variable.
Basically till i do a
NetObject.getImdscannedconfig(). it doesn't do a second load.
When i do a
Imdscannedconfig testimds = new Imdscannedconfig();
List lstImds = session.createCriteria(testimds.getClass()).list();
It does two SQL queries to load the Imdscannedconfig object first and then does a second query to load the Net Object as well even though i have not accessed the Instance Variable testimds. I need to avoid this second query.
When i load a Imdscannedconfig object, i don't need to load the Net Object.
Net[1] <-> Imdscannedconfig[0..*]
When i load a net object, i want the Imdscannedconfig object to be loaded when i call the getter method, which when i set Lazy="true" on the Set object works.
But when i load a imdscannedconfig, i don't want it load the net object. Can this be done?
I hope my question is clear now.
Thanks,
Surya