[英]JPA Criteria API - joining ElementCollection with WHERE condition on ElementCollection foreign key
[英]JPA - ElementCollection of foreign key
我尝试在实体A中映射Set<String>
,每个字符串都引用实体B的主键。
我坚持认为: 它必须是对密钥的引用。 不是整个实体 ...我已经知道如何制作@ ManyToOne,@ OneToMany等等,等等...;)
例如:
@Entity
public class A {
(...)
@Id
@GeneratedValue
private long id;
// Here is the problem: I want the siren as a foreign key of entity B
@ElementCollection
private Set<String> b_ids;
(...)
}
@Entity
public class B {
(...)
@Id
private String id;
(...)
}
编辑:我试图重新提出问题:有没有一种方法来存储实体的唯一ID的集合,但是具有到外键的链接(以及对ManyToMany等的检查和控制)?
它应该与几个附加注释一起使用。 来源: https : //javabydeveloper.com/mapping-collection-of-basic-value-types-jpa-with-hibernate/
@Entity
public class A {
(...)
@Id
@GeneratedValue
private long id;
@ElementCollection
@CollectionTable(name="B", joinColumns=@JoinColumn(name="id"))
@Column(name="id")
private Set<String> b_ids;
(...)
}
因此,添加了CollectionTable和Column批注。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.