Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 在实体中找不到@IdClass的属性_Hibernate_Jpa - Fatal编程技术网

Hibernate 在实体中找不到@IdClass的属性

Hibernate 在实体中找不到@IdClass的属性,hibernate,jpa,Hibernate,Jpa,我使用SpringBoot2、jpa和hibernate 使用此代码 @Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) public class Samplings { @Id @GenericGenerator(name = "samplings_id_seq", strategy="com.lcm.model.SamplingSequenceGenerator") @GeneratedValu

我使用SpringBoot2、jpa和hibernate

使用此代码

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class Samplings {

    @Id
    @GenericGenerator(name = "samplings_id_seq", strategy="com.lcm.model.SamplingSequenceGenerator")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "samplings_id_seq")
    private Integer id;

    @OneToMany(mappedBy = "sampling")
    private List<Samples> samples = new ArrayList<>();

}   

@Entity
@IdClass(SamplesPK.class)
public class Samples  {

    @Id
    private String sampleLetter;

    @Id
    @ManyToOne(optional = false)
    @JoinColumns({
        @JoinColumn(name = "id", referencedColumnName = "id")})
    private Samplings sampling;
}   

public class SamplesPK implements Serializable {

    private Integer id;

    private String sampleLetter;

    public SamplesPK(Integer id, String sampleLetter) {
        this.id = id;
        this.sampleLetter = sampleLetter;
    }

    .... //get / set
}
@实体
@继承(策略=InheritanceType.SINGLE_表)
公共类抽样{
@身份证
@GenericGenerator(name=“samplings\u id\u seq”,strategy=“com.lcm.model.SamplingSequenceGenerator”)
@GeneratedValue(策略=GenerationType.SEQUENCE,generator=“采样\u id\u seq”)
私有整数id;
@OneToMany(mappedBy=“采样”)
私有列表样本=新的ArrayList();
}   
@实体
@IdClass(SamplesPK.class)
公共类样本{
@身份证
私有字符串样本字母;
@身份证
@多通(可选=假)
@连接柱({
@JoinColumn(name=“id”,referencedColumnName=“id”)}
私人抽样;
}   
公共类SamplesPK实现了可序列化{
私有整数id;
私有字符串样本字母;
公共SamplesPK(整数id,字符串sampleLetter){
this.id=id;
this.sampleLetter=sampleLetter;
}
..//get/set
}
我得到这个错误:

org.hibernate.AnnotationException:在实体com.lcm.model.Samples::id中找不到@IdClass的属性


主键类中的字段或属性的名称与实体的主键字段或属性的名称必须对应,并且它们的类型必须相同。来自文档

您的
示例
类的id应该与您的
示例PK
的类型相同


示例

中应该有一个
@Id private Integer Id
,您的示例实体中似乎缺少SamplesPk.class的某些组件

它被称为样本::samplingId

这里有一个例子

编辑:

因此,您的实体应如下所示:

@Entity
@IdClass(SamplesPK.class)
public class Samples  {

    @Id
    private String sampleLetter;

    @Id
    private Integer id;

    @Id
    @ManyToOne(optional = false)
    @JoinColumns({
        @JoinColumn(name = "sampling_id", referencedColumnName = "id")})
    private Samplings sampling;
}   

事实上不工作,因为id hibernate不提供id fieldSamplesPK有“id”,而Samples没有。然后呢?