File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes missing property FetchType.EAGER in entityManger.find ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "missing property FetchType.EAGER in entityManger.find ?" Watch "missing property FetchType.EAGER in entityManger.find ?" New topic

missing property FetchType.EAGER in entityManger.find ?

nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
Does JPA2 has any method something like:

So I do not need to set up all my relationships within Users-class to fetchtype.eager.

Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

No. Its usually the exception rather than the rule to define collections to be eagerly fetched, this is because it is easy to override fetching behaviour in a specific query, but the performance overhead of always bringing back a whole object graph is not usually desirable (though this may be different in your case).

Its easy enough to write a method to do what you want though. Your DAO class could create a query by id as required which would be what I'd recommend.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
yes, I can create a query for that.

However, it would be nice to have such a feature to find-Method. Maybe in jpa3..;)

James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
JPA does not, but some providers do.

With JPA you could use a JPQL query that uses join fetch to make relationships fetched.

With EclipseLink you can use a LoadGroup or FetchGroup with a query through a query hint that defines what you wish to be loaded.

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
I agree. Here's the link:
subject: missing property FetchType.EAGER in entityManger.find ?
It's not a secret anymore!