-->
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.  [ 1 post ] 
Author Message
 Post subject: JPA - Hibernate does not return distinct results for a query
PostPosted: Tue Jun 23, 2009 9:59 am 
Newbie

Joined: Tue Jun 23, 2009 9:49 am
Posts: 3
Hello,

I found this link which explains why you can get too many results form an outer join with HIbernate:
https://www.hibernate.org/117.html

However I have a similar problem with JPA (simplified Entry class below).

I as I do expect the 'parts' list to have an ordered list including duplicate entries the LinkedHashMap solutions doesn't look like it will work.

If I make the collections lazy loaded then the results seem fine, but I am unable to show the them in a JSF page as the transaction and session has ended.

Any help please :)

Neil

@Entity
public class Entry implements Serializable, Comparable<Entry>
{
private List<TypedPart> parts;
private String id;
private Set<Category> categories;

@Id
public String getId()
{
return id;
}

public void setId(String id)
{
this.id = id;
}


protected void setParts(List<TypedPart> parts)
{
this.parts = parts;
}

@ManyToMany(fetch = FetchType.EAGER)
public List<TypedPart> getParts()
{
return parts;
}

public int hashcode()
{
return id.hashcode();
}

public boolean equals(Object obj)
{
boolean equal = obj instanceof Entry;

if (equal)
{
Entry other = (Entry) obj;

int size = getParts().size();
equal = other.getParts().size() == size;

for (int i = 0; i < size && equal; i++)
{
equal = getParts().get(i).equals(other.getParts().get(i));
}
}

return equal;
}

@ManyToMany(cascade =
{ CascadeType.MERGE, CascadeType.PERSIST }, fetch = FetchType.EAGER)
public Set<Category> getCategories()
{
return categories;
}

protected void setCategories(Set<Category> categories)
{
this.categories = categories;
}
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.