java – JPA @ElementCollection列表指定连接列名

前端之家收集整理的这篇文章主要介绍了java – JPA @ElementCollection列表指定连接列名前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下实体:
  1. @Entity
  2. public class Shirt implements Serializable {
  3.  
  4. @Id
  5. @Size(max=9)
  6. private String id;
  7.  
  8. @ElementCollection
  9. @CollectionTable(name="SHIRT_COLORS")
  10. @Column(name="color")
  11. private List<String> colors = new ArrayList<String>();
  12. ...

当我将hibernate设置为autocreate时创建的集合表是

  1. SHIRT_COLORS
  2. shirt_id
  3. color

如何注释我的实体,以便连接列不是实体和pk的连接,以便创建的表是:

  1. SHIRT_COLORS
  2. id
  3. color

我试过@JoinColumn,但没有工作.实际上,生产中的SHIRT_COLORS表在应用程序之外进行管理,列名称已经定义.

解决方法

尝试这个:
  1. @Entity
  2. public class Shirt implements Serializable {
  3.  
  4. @Id
  5. @Size(max=9)
  6. private String id;
  7.  
  8. @ElementCollection
  9. @CollectionTable(
  10. name = "SHIRT_COLORS",joinColumns=@JoinColumn(name = "id",referencedColumnName = "id")
  11. )
  12. @Column(name="color")
  13. private List<String> colors = new ArrayList<String>();
  14. ...

猜你在找的Java相关文章