[英]JPA @ElementCollection List specify join column name
I have the following entity: 我有以下实体:
@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>();
...
The collections table created when I set hibernate to autocreate is 我将hibernate设置为autocreate时创建的集合表是
SHIRT_COLORS
shirt_id
color
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: 如何注释我的实体,以便连接列不是实体和pk的串联,以便创建的表是:
SHIRT_COLORS
id
color
I've tried @JoinColumn but that didn't work. 我试过@JoinColumn但是没用。 In actuality, the SHIRT_COLORS table in production is managed outside of the app and the column names are already defined.
实际上,生产中的SHIRT_COLORS表在应用程序之外进行管理,并且已经定义了列名。
Try this: 试试这个:
@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>();
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.