Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JPA@ElementCollection列表指定联接列名_Java_Jpa - Fatal编程技术网

Java JPA@ElementCollection列表指定联接列名

Java JPA@ElementCollection列表指定联接列名,java,jpa,Java,Jpa,我拥有以下实体: @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 Arr

我拥有以下实体:

@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>();
    ...
如何注释实体,使联接列不是实体和pk的串联,从而创建的表是:

SHIRT_COLORS
 id
 color
我试过@JoinColumn,但没用。实际上,生产中的SHIRT_COLORS表是在应用程序之外管理的,并且已经定义了列名。

尝试以下操作:

@实体
实现可序列化的公共类{
@身份证
@尺寸(最大值=9)
私有字符串id;
@元素集合
@收集表(
name=“衬衫颜色”,
joinColumns=@JoinColumn(name=“id”,referencedColumnName=“id”)
)
@列(name=“color”)
私有列表颜色=新的ArrayList();
...

可以工作,但需要进行如下轻微编辑:referencedColumnName=“id”)。@jeff:对。当
referencedColumnName
用于
CollectionTable
映射时,引用列(
id
)位于包含集合的实体的表中。我已相应地更新了代码。谢谢您的评论,jeff。
SHIRT_COLORS
 id
 color