JPA主键集合

时间:2013-01-15 02:25:19

标签: 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 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;
}

我意识到这似乎打败了ORM的目的,但是能够遍历大对象而不必完全解析它们是有益的(嵌入式ID对象用于系统中的其他位置)。有没有办法做到这一点?

1 个答案:

答案 0 :(得分:0)

您应该能够使用ElementCollection映射。

请参阅, http://en.wikibooks.org/wiki/Java_Persistence/ElementCollection#Basic_Collections