两个表之间的JPA实体映射

时间:2015-03-26 14:54:06

标签: jpa entity

我的实体映射一直出现以下错误。

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;
    }
}

1 个答案:

答案 0 :(得分:3)

您使用

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

,但带注释的关联是

Swbhxml getSwrhxml()
             ^
             |___ r here

您的getter和setter命名不正确。坦率地说,有了这些神秘而密切的实体名称,你可能会有很多这样的错误。