Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

JPA Relational Mapping

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a question on retrieving the entities from JPA

Consider a employee entity



Dept Entity



If i have an dept id and want to get all employees, the only option i see is


This will fire two queries, one on the dept and then on employees (lazy loading)
But i am interested only in employees, there are no options in jpa to get this even using query (as there are no dept id in employee object). The reason i am asking is, when i am interested only in Employee, why to query Dept (what if it has 100's of more attributes which are not relevant).

Kindly let me know if this is the only way to resolve.

Thanks in advance
Rudresh
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about,



or,



Of coarse if the Department was already in the cache, the find on it and access to its employees would be the most efficient way to access the employees.
 
The human mind is a dangerous plaything. This tiny ad is pretty safe:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!