Hi!
I have a small problem, have looked around for a while without success, so I thought I would ask for some help.
Here the problem: I have a many-to-many mapping between users and groups that I want to define using a JPA ORM.
My classes are:
Code:
public class User implements Comparable<User> {
private String name;
protected SortedSet<Group> groups;
public User() { this.groups = new TreeSet<Group>(); }
public synchronized String getName() { return name; }
public synchronized void setName(String name) { this.name = name; }
public synchronized boolean equals(Object obj) { [...] }
public synchronized int hashCode() { [...] }
public synchronized int compareTo(User otherUser) { [...] }
}
public class Group implements Comparable<Group> {
private String name;
public SortedSet<User> users;
public Group() { this.users = new TreeSet<User>(); }
public synchronized String getName() { return name; }
public synchronized void setName(String name) { this.name = name; }
public synchronized boolean equals(Object obj) { [...] }
public synchronized int hashCode() { [...] }
public synchronized int compareTo(Group otherGroup) { [...] }
}
Here is my mapping:
Code:
<entity name="User" class="foo.bar.User">
<table name="USERS" />
<attributes>
<id name="name">
<column name="NAME" unique="true" nullable="false" />
</id>
<many-to-many name="groups" mapped-by="users">
<order-by>name</order-by>
<join-table name="USER_GROUP_MAPPINGS">
<join-column name="USER_NAME" nullable="false" />
<inverse-join-column name="GROUP_NAME" nullable="false" />
</join-table>
</many-to-many>
</attributes>
</entity>
<entity name="Group" class="foo.bar.Group">
<table name="GROUPS" />
<attributes>
<id name="name">
<column name="NAME" unique="true" nullable="false" />
</id>
<many-to-many name="users" mapped-by="groups" />
</attributes>
</entity>
And my problem is...
org.hibernate.AnnotationException: A sorted collection has to define @Sort: foo.bar.User.groups
at org.hibernate.cfg.annotations.CollectionBinder.bind(CollectionBinder.java:364)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1614)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:754)
...
I don't even know where I could put a <sort> element in the mapping, it is not even in the XSD :o/
Thanks for your help,
Nicolas.
Code: