使用@EmbeddedId和Foreign键,我在使用双向一对一映射时遇到了一些麻烦。
每次执行em.find(Bkftd03,Bkftd03PK.class)
y时都会获得相同的错误:
Error performing load command : org.hibernate.TypeMismatchException:
Provided id of the wrong type for class com.ibc.gsr.entity.Bkftd03. Expected: class com.ibc.gsr.entity.Bkftd03PK, got class com.ibc.gsr.entity.Bkftd27PK
主表结构如下所示:
Entity
@Table(name="BKFTD03")
@NamedQuery(name="Bkftd03.findAll", query="SELECT b FROM Bkftd03 b")
public class Bkftd03 implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private Bkftd03PK id;
@OneToOne
@JoinColumns({
@JoinColumn(name="PRO_NUM_PROPUESTA", referencedColumnName="PRW_NUM_PROPUESTA", nullable=false)
})
private Bkftd27 bkftd27;
反向映射表:
@Entity
@Table(name="BKFTD27")
@NamedQuery(name="Bkftd27.findAll", query="SELECT b FROM Bkftd27 b")
public class Bkftd27 implements Serializable {
@EmbeddedId
private Bkftd27PK id;
@OneToOne(mappedBy="bkftd27")
private Bkftd03 bkftd03;
两个实体的PK:
@Embeddable
public class Bkftd03PK implements Serializable {
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;
@Column(name="PRO_NUM_PROPUESTA", nullable=false, precision=12, columnDefinition="NUMBER(12,0)")
private long proNumPropuesta;
.....
@Embeddable
public class Bkftd27PK implements Serializable {
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;
@Column(name="PRW_NUM_PROPUESTA",nullable=false, precision=12, columnDefinition="NUMBER(12,0)")
private long prwNumPropuesta;
.......
我做错了什么?