-->
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: OneToMany Mapping returns duplicate entries
PostPosted: Mon Nov 12, 2007 8:14 pm 
Newbie

Joined: Mon Nov 12, 2007 7:59 pm
Posts: 1
Hibernate Version 3.3
I am using hibernate with spring 2.0 with MySQL 5.1
I have a table ContentEntry and then Another Table ContentRating
I have annotated the ContentEntry entity like the following.

@OneToMany(fetch = FetchType.EAGER, mappedBy="entryid",targetEntity=ContentEntryRating .class)
public Set<ContentEntryRating> getContentEntryRatings() {
return contentEntryRatings;
}

The problems i find is once the ratings are persisted any lookup on ContentEntry is returning multiple copies of the same entry.
There is no duplicates in DB

I tried to use a mapping table
I tried a mapping table as well now my mapping looks like this
@OneToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "T_CONTENT_RATING_MAP",
joinColumns = {
@JoinColumn( name = "CONTENT_ENTRY_FK" )
},
inverseJoinColumns = {
@JoinColumn( name = "CONTENT_RATING_FK" )
}

public Set<ContentEntryRating> getContentEntryRatings() {
return contentEntryRatings;
}


A criteria.list on a table of content_entry with a single row will return 10 elements in the list if there are 10 entries in the rating table?


Thanks in Advance for any help.

By the way i read in some docs that hibernate can't return distinct values and i need to paginate so can't use transformer..
Does this limit really exist even now?


Top
 Profile  
 
 Post subject: Re: OneToMany Mapping returns duplicate entries
PostPosted: Tue Dec 04, 2007 5:09 pm 
Newbie

Joined: Tue Aug 14, 2007 8:04 pm
Posts: 1
praveengeorge wrote:
Hibernate Version 3.3
ContentEntry is returning multiple copies of the same entry.
There is no duplicates in DB

praveengeorge, were you able to resolve this problem? I'm having a similar issue.


Top
 Profile  
 
 Post subject: Seems to be an Outer Join issue (with fetch = EAGER)
PostPosted: Mon Mar 03, 2008 5:26 pm 
Regular
Regular

Joined: Wed Dec 21, 2005 6:57 pm
Posts: 70
There's a long dissussion about how/why hibernate creates many duplicate entries in query results if an outer-join is used. This must be getting triggered for EAGER-ly loaded OneToMany and ManyToMany relations.

See: http://www.hibernate.org/117.html

My workaround is to make the mapping lazy. Changing from Bag semantics to set (use a hashset) should also work, but I haven't tried it.


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.