JPA @ElementCollection List指定连接列名称 [英] JPA @ElementCollection List specify join column name
本文介绍了JPA @ElementCollection List指定连接列名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下实体:
@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>();
...
将休眠设置为自动创建时创建的collections表是
The collections table created when I set hibernate to autocreate is
SHIRT_COLORS
shirt_id
color
如何注释实体,以便联接列不是实体和pk的串联,所以创建的表是:
How do I annotate my Entity so that the join column isn't a concatenation of the entity and pk so that the the table created is:
SHIRT_COLORS
id
color
我尝试了@JoinColumn,但是没有用.实际上,生产环境中的SHIRT_COLORS表是在应用程序外部进行管理的,并且列名已经定义.
I've tried @JoinColumn but that didn't work. In actuality, the SHIRT_COLORS table in production is managed outside of the app and the column names are already defined.
推荐答案
尝试一下:
@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>();
...
这篇关于JPA @ElementCollection List指定连接列名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文