Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

missing property FetchType.EAGER in entityManger.find ?

 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, I can create a query for that.

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

thanks.
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic