-->
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: search in set and sort does not work
PostPosted: Tue May 11, 2010 2:14 am 
Newbie

Joined: Tue Nov 02, 2004 5:37 pm
Posts: 17
Greetings,

i have this scenario with hibernate 3.2.5 and i'd like your help.

i have a department , employee relationship where in mapping i have :

<class name="Department" table="department">
....
<set name="employee">
<key column="employee_id" />
<one-to-many class="Employee" />
</set>
....

and the employee
<class name="Employee" table="employee">
....
<many-to-one name="department" class="Department" column="department_id" />
....

I am trying to query where department name is 'test' and the address of the employee is 'test ad'. The result should be sorted by the department id and the employee name. After a lot of search i ended up with this query :

select distinct d from Department d inner join fetch d.employee e where d.name='test' and e.address.street='test ad' order by d.id, e.name asc

1) Without the distinct the result is cartesian so i get duplicated (and more) rows (although the various posts mentioned that distinct would not be necessary). Why is this happening ?
2) The sort does not work at all. I always get random results.

I appreciate your replies.

Regards


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.