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

Java 多对一主键表示在实体上找不到属性,java,entity-framework,hibernate,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; @ManyToO

我有一个父实体和子实体,如下所示

家长

@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)

在我的场景中,我将父表字段以及主键设置在子表中。

请正确设置问题的格式。这增加了有人调查此事的机会。我以这个问题为例,你真的在每个类中有两个Id注释吗?我认为这不应该起作用,两个身份证起作用了。但在第二节课上,只有我遇到了问题。有趣的是,它正在创建子表,其中s1、s2字段作为主键,PK21也是如此。@Rooban您的映射很奇怪:您想实现一对一的关系吗?Test1引用Test2和Test2引用Test1?