views:

85

answers:

3

Hi.

I've got a Hibernate object which's properties are all loaded lazy. Most of these properties are other Hibernate objects or PersistentSets.

Now I want to force Hibernate to eager load these properties for just one time.

Of course I could "touch" each of these properties with object.getSite().size() but maybe there's another way to achieve my goal.

Thank you for your help.

A: 

According to the hibernate docs, you should be able to disable lazy property loading by setting the lazy attribute on your particular property mappings:

<class name="Document">
  <id name="id">
    <generator class="native"/>
  </id>
  <property length="50" name="name" not-null="true"/>
  <property lazy="false" length="200" name="summary" not-null="true"/>
  <property lazy="false" length="2000" name="text" not-null="true"/>
</class>
dogbane
I dont wan't to change the configuration, which is set lazy. I just want to achieve eager loading for one instance.
Bernhard V
A: 

Dozer works well for this type of thing - you can ask Dozer to map the object to another instance of the same class, and Dozer will visit all objects reachable from the current object.

See this answer to a similar question and my answer to another related question for more details.

matt b
+1  A: 

The documentation puts it like this:

You can force the usual eager fetching of properties using fetch all properties in HQL.

References

Pascal Thivent