-->
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: Joining four tables, result contains duplicate rows
PostPosted: Wed Jan 16, 2008 8:36 am 
Newbie

Joined: Wed Jan 09, 2008 2:52 pm
Posts: 1
Hi
I have a Hiberanate query

return getSession().find(select s.brCode, sa.id, sc.status sa.valid from BranchPOJO s join s.XYZs sa join sa.ABCs sab join sab.EFGs where
+ someclause);
(someclause is the where clause --- generated from the fields selected from the screen)

My issue is the result has duplicates in it

each row is fetched 6 times
can anyone point me to the solution?


My data model
|----- - - -SIN--------------------------------------------------------------|
| |
|----<-LOC- - ---<-EFG->--- - -ABC>--- - -XYZ >--- - -Branch->----|


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 16, 2008 1:51 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Your data model doesn't come out well in your question.
In any case, when you have joins, all tables involved except the lowest-level one are bound to have repeated values.
Play adding more or less conditions to your "where" condition. Also play with the joins, doing more or less joins to check at what point you start getting duplicate values.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 16, 2008 11:05 pm 
Beginner
Beginner

Joined: Wed Jul 11, 2007 7:21 pm
Posts: 21
Location: San Diego, CA
Dump the find() method; it's useful for simple stuff, but lacks any power. Upgrade to IQuery: much more powerful. When you do, you can use this:

query.SetResultTransformer(NHibernate.CriteriaUtil.DistinctRootEntity);


Same thing for Hibernate, but I'm sure you get the idea. It works when returning whole objects; not sure what happens when you grab properties alone.

_________________
http://rebelheart.squarespace.com


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.