Why doesn't the JPA offer the loadChildren () method for lazily loaded relationships?

There are times when I want to define relationships as lazily loaded, since 90% of the time when I do not want child entities, but they also have the ability to immediately get the entire hierarchy under certain circumstances. I do not want to achieve this using a named query, as the parent-child hierarchy is useful when I convert, for example. JSON Right now my dirty hack is to call .getChildEntities (). Size () to force lazy loading in a single transaction.

Is there a better way?

+4
source share
2 answers

Depends on JPA implementation. Some (most) will load everything with this method call, which you quote, but some may issue a COUNT (*) request to get the size also for memory management reasons (not wanting to load all elements for cases when there are a lot of them)

- Andy ( DataNucleus )

+2
source

Maybe you can use the JOIN FETCH clause

http://download.oracle.com/docs/cd/E16764_01/apirefs.1111/e13046/ejb3_langref.html#ejb3_langref_fetch_joins

chapter: 10.2.3.5.3. Jpg fetch joins

0
source

All Articles