gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 12:18:28 24 4
gpt4 key购买 nike

我使用 spring boot 2、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
}

我收到此错误:

org.hibernate.AnnotationException: Property of @IdClass not found in entity com.lcm.model.Samples:: id

最佳答案

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

您的 Samples类的 ID 应该与您的 SamplesPK 的类型相同.

你应该有一个 @Id private Integer id在您的 Samples类(class)

关于hibernate - 在实体中找不到@IdClass 的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52861677/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com