-
1. Re: Using own Classes as member for ManyToMany-Assotiations
dkalna Feb 7, 2007 5:17 AM (in response to micho)Hi micho,
IMHO you ain't free to implement your own Collections for EJB3 associations, you have to stick with those in java.util package.
hm, but I'm not sure...
Bye
Dalibor -
2. Re: Using own Classes as member for ManyToMany-Assotiations
drgorb Feb 9, 2008 8:56 AM (in response to micho)After reading your post (I had the same problem) I tried every descendant of java.util.Collection. It worked only with java.util:collection itself.
the nice thing is that without specifying anything, JBoss created a link table between the two entities. Which is what should be done.
example:
/**
* @return the roles
*/
@ManyToMany(
targetEntity=Role.class,
cascade={CascadeType.PERSIST, CascadeType.MERGE}
)
public Collection < Role > getRoles() {
if(roles == null) {
roles = new LinkedList < Role >();
}
return roles;
}
/**
* this setter must exist for hibernate but be private because we don't want anyone to use it
* @param roles the roles to set
*/
@SuppressWarnings("unused")
private void setRoles(Collection < Role > roles) {
this.roles = roles;
}
When the Roles are read from the database, the Class used for the roles Collection is org.hibernate.collection.PersistentBag
It would actually be nice to be able to choose a type that disallows duplicates in the list. Because now I have to catch the exception upon "persist".