Hibernate collections with a table with no key column
I have 2 tables one like this. I'm using hibernate version 3.6.5.
@Entity
public class User implements java.io.Serializable {
@Id
private Integer id;
private String userName;
private List<String> costCenters;
}
I have another table like this: TableUserCostCenter
username costcenter
user1 xxxx
user1 xxx1
user1 xxx2
user1 xxx3
user2 xxx3
user3 xxx3
user4 xxx3
I want my User to get a list with all the costCenters
on a usere开发者_如何学编程ntity
. Is there any good way to do this with annotations on an entity?
Look at the annotations http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/#entity-hibspec-collection. They provide the annotation to map a collection.
精彩评论