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; } }
|