-->
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: The query returns duplicate rows!!!
PostPosted: Mon Dec 04, 2006 1:24 am 
Newbie

Joined: Thu Oct 05, 2006 11:34 am
Posts: 8
I have got two entity objects Bug and User associated with each other by Many To Many relations

The association is defined in this fashion in both Bug.java and User.java

@ManyToMany(targetEntity = User.class, cascade = { CascadeType.PERSIST,
CascadeType.MERGE })
@JoinTable(name = "BUG_USER", joinColumns = { @JoinColumn(name = "BUG_ID") }, inverseJoinColumns = { @JoinColumn(name = "USER_ID") })
public List<User> getUsers() {
return users;
}


@ManyToMany(cascade = { CascadeType.MERGE, CascadeType.PERSIST }, mappedBy = "users", targetEntity = Bug.class)
public List<Bug> getBugs() {
return bugs;
}

When i tried to fetch the all the Bugs along with its associated result using the following code snippet:

@SuppressWarnings("unchecked")
public List<Bug> findAllBugs() {
Session session = getHibernateTemplate().getSessionFactory()
.getCurrentSession();
String SQL_QUERY = "from Bug bug inner join fetch bug.users";

log.info(SQL_QUERY);
Query query = session.createQuery(SQL_QUERY);
return query.list();
}

it returned duplicate rows.

For example if i assign a bug say A to two users say B and C,
then two rows are returned for the same bug id and same assigned users.

If i assign one bug to three users,then three duplicate rows are returned.

_________________
.::hIBERNATe rOCKs::.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 04, 2006 1:59 am 
Regular
Regular

Joined: Mon Nov 24, 2003 6:36 pm
Posts: 105
maybe this applies

http://www.hibernate.org/117.html#A12
?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 04, 2006 6:18 am 
Newbie

Joined: Thu Oct 05, 2006 11:34 am
Posts: 8
Thanx man it worked

_________________
.::hIBERNATe rOCKs::.


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.