Hi,
I'm trying to define the fetch strategy for lazy associations using JPA/Hibernate 3.2.6. It seems the @Fetch annotation is only valid for eager associations. Well, at least, I couldn't make it work otherwise. Please, prove me wrong. :-)
The main reason I'm trying this is because:
(1) I don't want a model-driven way to define which association is lazy and which isn't.
Mainly because there are various ways of using the entity model; each with their
own requirements about which association is needed and which isn't. If I put it all
eager, I'm pulling the whole database in.
(2) The resulting graph is serialized and sent to a different machine. This machine does
not has the possibility to pull lazily the associated objects. As such, the required
objects should already been pre-loaded.
I though I could have all associations set lazy and pull them in with a FETCH JOIN to overrule the lazy setting. This way the developer defines which associations should be filled-in for his particular usage.
This works *but* it doesn't use separate queries to load the associated objects. It all comes with one big query full of outer joins. which should be made distinct to eliminate duplicated values. Some objects have quite some optional associations, so this becomes quite painful for the database.
Of course it would work to have the developers run the main query without joins and let them fill in the associations lazily by calling the related accessor methods. But I was hoping to keep it simple by just defining one JPQL query with the required associations.
Any idea how I can pull it off with just one query and some configuration ?
Many thanks !!
Jan
|