-->
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: multiple @ManyToOne relations break join fetch semantics
PostPosted: Mon Feb 17, 2014 7:35 am 
Newbie

Joined: Mon Feb 17, 2014 6:21 am
Posts: 1
When Entity has more than one @ManyToOne (unidirectional) relations to some other entity,
HQL query with left join fetch makes N+1 selects. This does not happen without multiple @ManyToOne relations to the same entity.

Example:

Code:
@Entity
public class Country {
   @Id
   private String name;
}

@Entity
public class Person {
   @Id
   private Integer personId;

   @ManyToOne
   private Country nationality;

   @ManyToOne
   private Country taxDomicile;

}



Now, this HQL:

Code:
  session.createQuery("from Person p left join fetch p.nationality left join fetch p.taxDomicile")


makes N+1 selects - main select from Person entity and then selects from Country for each row in Person.
When there is only one relation to Country entity (e.g. delete taxDomicile field) join fetch works correctly (only one select joining Person and Country).

Is this behaviour known? Is it a feature, Is it a bug?
Tested on 4.3.1.Final


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.