我有以下多重性: Order3d 1 ----- 1 .. * DrawFile 1 ----- 1 .. * Order3dLineJPA插入失敗,因爲在零值,我的外鍵
而且我當我想保存Order3d對象我得到一個約束衝突,因爲DrawFile.id放在我Order3dLine領域,我在國外鍵得到了零值:
Hibernate: insert into order3d (delivery, demand_date, estimate_date, order_date, person_id, state) values (?, ?, ?, ?, ?, ?) //OK
Hibernate: insert into draw (dimension, filename, format, hashname, hole, order3d_id, readable, size, slope, wall) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) //OK
Hibernate: insert into order3dline (duration, produced, quantity, color, draw_id, material) values (?, ?, ?, ?, ?, ?)
09:33:08,779 TRACE BasicBinder:84 - binding parameter [1] as [SMALLINT] - 0
09:33:08,780 TRACE BasicBinder:84 - binding parameter [2] as [SMALLINT] - 0
09:33:08,780 TRACE BasicBinder:84 - binding parameter [3] as [SMALLINT] - 2
09:33:08,781 TRACE BasicBinder:84 - binding parameter [4] as [INTEGER] - 0
09:33:08,781 TRACE BasicBinder:84 - binding parameter [5] as [INTEGER] - 0 //NOT OK
09:33:08,782 TRACE BasicBinder:84 - binding parameter [6] as [VARCHAR] - Something
我的Java類是像這(我沒有把所有的屬性和方法,因爲我猜這是不相關的):
@Entity
@Table (name="draw")
public class DrawFile implements Serializable {
@OneToMany(mappedBy="draw", fetch = FetchType.EAGER, cascade=CascadeType.ALL)
private Set<Order3dLine> line3ds=new HashSet<Order3dLine>(3);
}
@Entity
@Table (name="order3dline")
public class Order3dLine implements Serializable {
private static final long serialVersionUID = 3993578603382571145L;
@EmbeddedId
private Order3dLine3dPK id=new Order3dLine3dPK();
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name = "draw_id", referencedColumnName="id", insertable = false, updatable = false)
private DrawFile draw;
}
@Embeddable
public class Order3dLine3dPK implements Serializable {
@Column(name="draw_id", columnDefinition="id", insertable=false, updatable=false)
private int drawId;
private String material="";
private int color;
}
註釋是否缺失?
您必須填寫您的FK並輸入有效的編號 –