gpt4 book ai didi

java - 执行 JPA 一对一时引用的属性未知

转载 作者:行者123 更新时间:2023-11-30 05:46:05 26 4
gpt4 key购买 nike

我有这 2 个实体,我想在执行 JPA 一对一时使用 SQL 数据库中的 @OneToOne 进行映射(表中的一条记录恰好对应于相关表中的一条记录)

这是我如何创建@OneToOne关系

@Entity
@Table(name = "IMP_Radio")
@NamedQuery(name = "ImpactRadio.findAll", query = "SELECT ia FROM ImpactRadio ia ")
public class ImpactRadio implements Serializable, IEntity<String> {

/**
*
*/
private static final long serialVersionUID = 1L;

@Id
@Column(name = "ID")
private String id;

@OneToOne(mappedBy = "impactRadio", fetch = FetchType.EAGER)
@JoinColumn(name = "IA_ID")
private ImpactRadioAmendment amendments;

@OneToOne(mappedBy = "impactRadio", fetch = FetchType.EAGER)
@JoinColumn(name = "IA_ID")
private ImpactRadioExamination examinations;


}




@Entity
@Table(name = "IMP_Radio_EXAMINATION")
public class ImpactRadioExamination implements Serializable, IEntity<String> {

/**
*
*/
private static final long serialVersionUID = 1L;

@Id
@Column(name = "ID")
private String id;

@OneToOne(cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
@JoinColumn(name = "IA_ID")
private ImpactRadio ImpactRadio;

}


But I have an exception when I try to run a Junit test
Caused by: org.hibernate.AnnotationException:
Unknown mappedBy in: com.tdk.persistence.fire.model.ImpactRadio.examinations,
referenced property unknown: com.tdk.persistence.fire.model.ImpactRadioExamination.impactRadio

最佳答案

这是因为这里需要传递字段名称:

@OneToOne(mappedBy = "impactRadio", fetch = FetchType.EAGER)
@JoinColumn(name = "IA_ID")
private ImpactRadioAmendment amendments;

@OneToOne(mappedBy = "impactRadio", fetch = FetchType.EAGER)
@JoinColumn(name = "IA_ID")
private ImpactRadioExamination examinations;

而实际字段是大写的:

@OneToOne(cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
@JoinColumn(name = "IA_ID")
private ImpactRadio ImpactRadio;

ImpactRadio 重命名为 impactRadio

关于java - 执行 JPA 一对一时引用的属性未知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54810348/

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