我有以下实体:
- @Entity
- public class Shirt implements Serializable {
- @Id
- @Size(max=9)
- private String id;
- @ElementCollection
- @CollectionTable(name="SHIRT_COLORS")
- @Column(name="color")
- private List<String> colors = new ArrayList<String>();
- ...
当我将hibernate设置为autocreate时创建的集合表是
- SHIRT_COLORS
- shirt_id
- color
如何注释我的实体,以便连接列不是实体和pk的连接,以便创建的表是:
- SHIRT_COLORS
- id
- color
我试过@JoinColumn,但没有工作.实际上,生产中的SHIRT_COLORS表在应用程序之外进行管理,列名称已经定义.
解决方法
尝试这个:
- @Entity
- public class Shirt implements Serializable {
- @Id
- @Size(max=9)
- private String id;
- @ElementCollection
- @CollectionTable(
- name = "SHIRT_COLORS",joinColumns=@JoinColumn(name = "id",referencedColumnName = "id")
- )
- @Column(name="color")
- private List<String> colors = new ArrayList<String>();
- ...