-->
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.  [ 3 posts ] 
Author Message
 Post subject: Criteria Api problem with @MayToMany
PostPosted: Fri Jul 06, 2007 11:08 am 
Newbie

Joined: Wed May 23, 2007 10:07 am
Posts: 12
Location: Italy
Sorry if i ask something that may be obvious.

I have two entity with a jointable cause there is a many to many association.
Example:
Teachers --> JOIN-TABLE <-- Students.

I have put inside the Teachers entity the @ManyToMany association.
Everthing works fine, cause i 'm able to get the students list for a choose teacher.

The problem comes when i do some queries using the Criteria Api.
I'd like for example to get 10 female teachers. The problem is that automatically hibernate execute the join with the Students table, so the result set contains duplicated entity. Then if I use the Criteria.DISTINCT_ROOT_ENTITY i remove the duplicate, but i get less than 10 results.

How can i solve the problem??

Thanks ;)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 5:35 am 
Newbie

Joined: Wed May 23, 2007 10:07 am
Posts: 12
Location: Italy
I found where the problem is.
The students list in the teacher entity il loaded eagerly.

The problem is that i'm not able to load it lazily, cause when i access it the session is already close. I'musing annotations and Spring+Struts.
Is there a way to open it again or to keep it open??

Thanks for any help


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 8:59 am 
Newbie

Joined: Wed May 23, 2007 10:07 am
Posts: 12
Location: Italy
I have found how to solve the problem:
Code:
criteria.setFetchMode("students",FetchMode.SELECT);


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.