两个表之间的 JPA 实体映射

JPA Entity Mappings between two tables

我的实体映射不断出现以下错误。

Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: edu.indstate.ics.transcript.web.dao.entity.Swrhxml.swbhxml in edu.indstate.ics.transcript.web.dao.entity.Swbhxml.swrhxmls

我不确定我做错了什么。可以就我在这里缺少的内容提供一些见解和帮助。

我的实体类如下:

@Entity
@Table(name = "SWBHXML" )
public class Swbhxml implements DatabaseObject, Serializable {
    private List<Swrhxml> swrhxmls;
    private static final long serialVersionUID = 1L;
    private Long swbhxmlTransId; 

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "SWBHXML_TRANS_ID", nullable = false)
    public Long getSwbhxmlTransId() {
        return swbhxmlTransId;
    }

    public void setSwbhxmlTransId(Long swbhxmlTransId) {
        this.swbhxmlTransId = swbhxmlTransId;
    }

    @OneToMany(mappedBy = "swbhxml", cascade = CascadeType.ALL)
    public List<Swrhxml> getSwrhxmls() {
        return swrhxmls;
    }

    public void setSwrhxmls(List<Swrhxml> swrhxmls) {
        this.swrhxmls = swrhxmls;
    }
}

@Entity
@Table(name = "SWRHXML" )
public class Swrhxml implements DatabaseObject, Serializable {

    private Swbhxml swbhxml;
    private static final long serialVersionUID = 1L;

    private Long SwrhxmlTransId;
    private String SwrhxmlHxpsCode;
    private Date SwrhxmlTimeStamp; 

    @ManyToOne(fetch = FetchType.EAGER) 
    @JoinColumn(name="SWBHXML_TRANS_ID")
    public Swbhxml getSwrhxml() {
        return swbhxml;
    }

    public void setSwrhxml(Swbhxml swbhxml) {
        this.swbhxml = swbhxml;
    }

    @Column(name = "SWRHXML_HXPS_CODE", length = 15)
    public String getSwrhxmlHxpsCode() {
        return SwrhxmlHxpsCode;
    }

    public void setSwrhxmlHxpsCode(String SwrhxmlHxpsCode) {
        this.SwrhxmlHxpsCode = SwrhxmlHxpsCode;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "SWRHXML_TIMESTAMP", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    public Date getSwrhxmlTimeStamp() {
        return SwrhxmlTimeStamp;
    }

    public void setSwrhxmlTimeStamp(Date SwrhxmlTimeStamp) {
        this.SwrhxmlTimeStamp = SwrhxmlTimeStamp;
    }
}

您使用

`mappedBy = "swbhxml"`
               ^
               |___ b here

,但是标注的关联是

Swbhxml getSwrhxml()
             ^
             |___ r here

您的 getter 和 setter 命名不正确。坦率地说,使用如此神秘和紧密的实体名称,您可能会遇到很多这样的错误。