-->
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: HQL Query result
PostPosted: Wed Nov 01, 2006 2:00 am 
Newbie

Joined: Wed Oct 18, 2006 7:29 am
Posts: 11
can anyone suggest me why this query gives duplicate results, despite of being only one in the database

public List<Bug> findAllBugs() {
Session session = getHibernateTemplate().getSessionFactory()
.getCurrentSession();
String SQL_QUERY = "from Bug as bug inner join fetch bug.users as users";
log.info(SQL_QUERY);
Query query = session.createQuery(SQL_QUERY);
return query.list();
}


i have a 2 table named USERS and BUGS mapped as many to many, so the association table is BUG_USER
+--------+---------+
| BUG_ID | USER_ID
+--------+---------+
| 4 | 1 |
| 4 | 2 |
+--------+---------+

here bug with id 4 is assigned to to users with id 1, and 2

so is there any thing wrong in the query
i m really sick with this......................


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 01, 2006 9:56 am 
Newbie

Joined: Mon Sep 18, 2006 6:34 am
Posts: 18
Hi puran,

if what I gather is correct then the query is returning the right data although to clarify it you might post up the contents of both tables. But if you have the following:

USER
ID NAME etc
1 Bob ...
2 Fred ...

and BUGS
ID USER_ID BUG_DATE etc
4 1 2006-10-31 ...
4 2 2006-11-01 ...

Then
+--------+---------+
| BUG_ID | USER_ID
+--------+---------+
| 4 | 1 |
| 4 | 2 |
+--------+---------+

will be right.

Generally though it wouldn't be considered right to have a many to many relationship and the primary keys would be broken up into an intermediate table USER_BUGS i.e.
USER_ID BUG_ID etc
1 4
2 4

and BUGS would change to
ID BUG_DATE etc
4 2006-11-01 ...

To search then you'd look at the intermediate table, USER_BUGS and use the foreign keys to look up user/bug data.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 03, 2006 5:48 am 
Newbie

Joined: Wed Oct 18, 2006 7:29 am
Posts: 11
hi johnny thanx for a reply

u got right but


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.