Typically Lazy initialization would be helpful in a many-to-one,one-to-many bi-directional relation.
To take your example, you have 3 entities here:
User
Order
Supplier
User and Order share a 1-to-many relation
Order and Supplier share a 1-1 relation
Let's say that a user want's to look at all his orders, you do a load on the User (with the userid or some selection criteria).
You User Object would have a collection that would represent the Orders that the user has.
In your Hibernate mapping say we define something like this:
Code:
<class name="User"...>
<set cascade="all" inverse="true" lazy="true" name="orders" table="ACMS_CPTR_ENC_DETAILS">
<key column="userId"/>
<one-to-many class="UserOrder"/>
</set>
..
</class>
When you do a session.load() or find(), the user object's collection would be populated only with Proxies to the UserOrder object and would not load the properties of the UserOrder.
Once you select the order, you selectively load the UserOrder from the collection using the collection's accessor methods, at this point, it would load and populate the properties of the UserOrder entity that you are trying to show to the user.
The supplier as part of the Order would also work in a similar fashion.
You can set the "hibernate.show_sql" property to "true" to find the difference.
Hope that helps. I am also a beginner to Hibernate and hoping that a more advanced user would give me a better explanation.
-Anand