Hibernate JPA - 映射到嵌入式ID

时间:2015-07-16 14:06:56

标签: java hibernate jpa mapping

我遇到了关于hibernate和映射到embeddedId的问题。

EntityB有一个复合键。我想从EntityA添加一个引用(ManyToOne)到EntityB的一个主键。 我尝试了几个建议,但没有成功。

@Entity
public class EntityA {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;

    private EntityB enB;
    --- plus constructor/getter and setter for hibernate
}

EntityB看起来像这样

@Entity
public class EntityB {

    @EmbeddedId
    private CompositeKey compKey;

    --- some more attributes of the class and the generic methods for hibernate
}

@Embeddable
class CompositePK {

    private int id;
    private int path;
    private int time;
...
}

我想从EntityA引用EntityB的“id”。我希望我解释它是可以理解的。谢谢!

0 个答案:

没有答案