开发者

Hibernate collections with a table with no key column

开发者 https://www.devze.com 2023-04-03 23:56 出处:网络
I have 2 tables one like this. I\'m using hibernate version 3.6.5. @Entity public class User implements java.io.Serializable {

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消