多对一和主键表示在实体上找不到属性

时间:2015-05-15 12:05:05

标签: java entity-framework hibernate

我有一个如下所示的父母和子女实体。

@Entity(name="Test1")
public class Test1 implements Serializable{

    @Id
    @Column(name="PK1")
    public int pk1;

    @Id
    @Column(name="PK2")
    public int pk2;

    @Column(name="fld")
    public int fld;

    @ManyToOne
    @JoinColumn(name="pt3l", referencedColumnName = "P1")
    public Test3 fldl;
}

儿童

@Entity(name="Test2")
public class Test2 implements Serializable{
    @Id
    @Column(name="PK21")
    public int pk21;

    @Id
    @ManyToOne
    @JoinColumns ({
        @JoinColumn(name="s1", referencedColumnName = "PK1"),
        @JoinColumn(name="s2", referencedColumnName = "PK2")
    })
    public Test1 fld21;

    @Column(name="FLD21")
    public int fld22;

}

当我在子ID中创建@ManyToOne字段时,我得到了以下错误。

Exception in thread "main" org.hibernate.MappingException: property [pk21] not found on entity [he.db.Test2]
    at org.hibernate.mapping.PersistentClass.getProperty(PersistentClass.java:458)
    at org.hibernate.mapping.PersistentClass.getProperty(PersistentClass.java:470)

在我的场景中,我已将父表字段作为子键中的主键。

0 个答案:

没有答案