Hibernate supports the feature of lazy initilasation for both entities and collections. What this actually means is, the Hibernate engine loads only those objects that we are querying for and doesnt try to fetch other entities(that are associated with the entity we are querying) or collections.
An attribute 'lazy' can be used to let Hibernate know if the associated entity or collection has to be lazily loaded or prefetched.
Ex:
<set name="Children" lazy="false" inverse="true">
<key column="FK_COL"/>
<one-to-many class="Parent"/>
</set>
This causes the collection to be eagerly fetched rather than doing a lazy fetch. If on the other hand , the attribute value of lazy is set to true, then hibernate will not make an attempt to fire the query for fetching the collection object until the request is made by the user.
Hope this answer helps.
Thanks Ravi.
Above answer was rated as good by the following members: JaiBharath, SitaPutta
when loading an obj that has a collection hibernate loads collection elements ONLY when actually you ask for them; so this improves performance among other advantages.
when u use hibernate u can make lazy true or lazy false.
Hibernate supports the feature of lazy initilasation for both entities and collections. What this actually means is the Hibernate engine loads only those objects that we are querying for and doesnt try to fetch other entities(that are associated with the entity we are querying) or collections.
An attribute 'lazy' can be used to let Hibernate know if the associated entity or collection has to be lazily loaded or prefetched.
Ex:
<set name "Children" lazy "false" inverse "true">
<key column "FK_COL"/>
<one-to-many class "Parent"/>
</set>
This causes the collection to be eagerly fetched rather than doing a lazy fetch. If on the other hand the attribute value of lazy is set to true then hibernate will not make an attempt to fire the query for fetching the collection object until the request is made by the user.
Lazy initialization load the child objects while loading parent object. To getting this set the lazy false in mapping file or class.lazy false in class file and hibernate will load the child when parent is loaded from the database. by default lazy is true.
Lazy false by default so the parent table can fetch the fields from child table also
Ex: A is a class which have sub class B
If you want to access the fields from both A and B then you have to write in A class as laze false (by default) when you write laze true then it won't fetch the fields from the B class If you have any comments please let me know
by default lazy true so that parent table wont fetch the fields from child table. so in that case u have to wite explicitly lazy false Then we can fetch the fields from the psrent as well as child fileds
Lazy loading means that any foreign key references that you have in your table will be loaded only when referred to by the application. Eager loading means everything will be loaded at once.