-->
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.  [ 2 posts ] 
Author Message
 Post subject: yet another duplicate result with criteria query question
PostPosted: Fri Feb 01, 2013 10:42 am 
Newbie

Joined: Fri Aug 25, 2006 8:35 am
Posts: 4
I am trying to figure out if there is a way to prevent Hibernate from adding in left outer joins of child tables when querying for entities with ManyToMany relationship with said children. So, I have a parent table A with a ManyToMany relationship with table B. I want to find all A'a so I...

hibernateSession.createCriteria(A.class).list();

Note that I am not including any restrictions involving B or any other relationship and that I have the ManyToMany annotation parameterized with fetch = FetchType.LAZY.

I am aware of the duplicate parent entity confusion that is covered in the FAQ, and understand why I would get duplicate A records for every B record if the Criteria would employ a left outer join on B because of a restriction or projection involving B. But, I do not understand why that left out join would be used in a straight select all. Also of interest, this is not new code and was working prior to us migrating from Hibernate 3.X to Hibernate 4.1. Can anyone point me to a resource (doc, forum post, blog post, etc.) that explains why Hibernate now behaves this way? Are there ways to change this behavior?


Top
 Profile  
 
 Post subject: Re: yet another duplicate result with criteria query question
PostPosted: Tue Feb 05, 2013 4:02 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
Are there ways to change this behavior?


There's a way to suppress the automatic join by specifying the fetchmode:

criteria.setFetchMode(relationAttributeName ,org.hibernate.FetchMode.SELECT);


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

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.