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: multiple results returned for one primary key
PostPosted: Wed Oct 22, 2003 2:43 am 
Beginner
Beginner

Joined: Wed Sep 24, 2003 3:14 am
Posts: 20
Location: Munich, Germany
Hi,

i use the following finder method to find a number of business objects by primary key:
Code:
public static List findByPrimaryKeys(Session pSession, List pKeys)
    throws HibernateException
{
    Query query = pSession.createQuery("select from BO1 as bo1 " +
                                       "left join fetch bo1.BO2s " +
                                       "where bo1.a in (:keys)");
    query.setParameterList("keys", pKeys);
    List back= query.list();

    return back;
}

The query works, but unfortunately it returns duplicate bo1 objects:
if pKeys contains one primary key, and that entity has 10 BO2
children, i get a query result of 10 BO1 objects, containing the same data.

If i remove the "left join fetch bo1.BO2s" line, everything works as expected, but of course with a lower performance.

I'm using Hibernate 2.1b4.

Any hints?

Bye,

J


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 3:37 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is expected behaviour. It is easy to unique-ify the results for yourself.


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.