-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Fetch multiple onetoMany relationships Hibernate JPA
PostPosted: Wed Oct 27, 2010 10:50 am 
Newbie

Joined: Wed Oct 27, 2010 10:36 am
Posts: 1
I am using Hibernate JPA 1.0.

I have the following type of model and I consider manyToOne and oneToOne relationships "eagerly" fetched and oneToMany "lazily" fetched.

I want to fetch Entity A and all its associations where a.id=?

  • A oneToMany B
then...
  • B oneToOne C
    + C oneToMany D
  • B oneToOne E
    + E oneToMany D
  • B oneToOne F
    + F oneToMany D
Is it possible to load this entity in a single query? Or in a subset of queries baring in mind the "n+1 selects problem"!
So far my solution to loading all of A associations was to perform the following:

Code:
"Select DISTINCT a from A a JOIN FETCH a.bs WHERE a.id=:aID"

And then iterate using code in order to fetch all other associations.
Code:
Collection B bs = A.getBs();

         for (final B b : bs) {
         b.getCs().getDs().size();
         b.getEs().getDs().size();
         b.getFs().getDs().size();
         }

Obviously there must be a better way of doing this.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.