加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-14 05:33:43 所属栏目:Java 来源:网络整理
导读:我有以下实体: @Entitypublic class Shirt implements Serializable { @Id @Size(max=9) private String id; @ElementCollection @CollectionTable(name="SHIRT_COLORS") @Column(name="color") private ListString colors = new ArrayListString(); ... 当
我有以下实体:
@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>();
    ...

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读