JPA主键集合
我希望创建一个主键集合(实际上是实体键的一对多关系,无需解析引用的实体) 比如说,JPA主键集合,jpa,jpa-2.0,primary-key,one-to-many,Jpa,Jpa 2.0,Primary Key,One To Many,我希望创建一个主键集合(实际上是实体键的一对多关系,无需解析引用的实体) 比如说, @Entity public class BigObject { @EmbeddedId private BigObjectId id; // lots of other stuff } @Embeddable public class BigObjectId { //fields here } @Entity public class Referrer { // This w
@Entity
public class BigObject {
@EmbeddedId
private BigObjectId id;
// lots of other stuff
}
@Embeddable
public class BigObjectId {
//fields here
}
@Entity
public class Referrer {
// This won't work since BigObjectId is an embeddable. I would like a join table
// REFERRER_BIGOBJECTS with a REFERRER_ID PK foreign key and a BIGOBJECT_ID PK
// foreign key.
@OneToMany
private Set<BigObjectId> bigObjectIds;
}
@实体
公共类大对象{
@嵌入ID
私有BigObjectId;
//还有很多其他的东西
}
@可嵌入
公共类BigObjectId{
//这里的田地
}
@实体
公共类推荐人{
//因为BigObjectId是可嵌入的,所以这不起作用。我想要一个联接表
//具有referer\u ID PK外键和BIGOBJECT\u ID PK的referer\u BIGOBJECTS
//外键。
@独身癖
私有集bigObjectId;
}
我意识到这似乎违背了ORM的目的,但能够遍历大型对象而不必完整解析它们是有益的(嵌入式ID对象用于系统中的其他位置)。有办法做到这一点吗?您应该能够使用ElementCollection映射 看,,
ElementCollection映射将允许BigObjectId的集合,但不允许这些是外键,并且无法指定级联操作。如果这是最好的,我可以尝试管理,以确保我自己的一致性。。。