1
有誰知道如何修復實體的映射?如何使用@EmbeddedId映射實體?
錯誤是
所致:org.hibernate.AnnotationException:在JoinColumns.referencedColumnName未發現 com.test.TableAa的列名ID。
TableAa實體
@Entity
@Table(name = "TABLE_AA")
public class TableAa {
@EmbeddedId
private TableAaPk pk;
@Column(name = "FIRST_NAME")
private String first_name;
@Column(name = "LAST_NAME")
private String last_name;
//@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
//@JoinColumns({
//@JoinColumn(name = "ID", referencedColumnName = "ID", insertable = false, updatable = false),
//@JoinColumn(name = "ACCOUNT_NUMBER", referencedColumnName = "ACCOUNT_NUMBER", insertable = false, updatable = false) })
@OneToMany(mappedBy = "tableAa", cascade = CascadeType.ALL)
private List<TableBb> tableBbList;
}
TableAaPk複合鍵
@Embeddable
public class TableAaPk implements Serializable{
private static final long serialVersionUID = 1L;
@Column(name="ID")
private String id;
@Column(name="ACCOUNT_NUMBER")
private String accountNumber;
}
TableBb實體
@Entity
@Table(name = "TABLE_BB")
public class TableBb {
@EmbeddedId
private TableBbPk pk;
@Column(name = "FIRST_NAME")
private String first_name;
@Column(name = "LAST_NAME")
private String last_name;
}
TableBbPk複合鍵
@Embeddable
public class TableBbPk implements Serializable{
private static final long serialVersionUID = 1L;
@Column(name="ID")
private String id;
@Column(name="ACCOUNT_NUMBER")
private String accountNumber;
@Column(name="CODE")
private String code;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "ID", referencedColumnName = "ID", insertable = false, updatable = false),
@JoinColumn(name = "ACCOUNT_NUMBER", referencedColumnName = "ACCOUNT_NUMBER", insertable = false, updatable = false) })
private TableAa tableAa;
}
格式的代碼,請 – Mistalis