簡體   English   中英

EntityManager.find方法導致MySQLIntegrityConstraintViolationException

[英]EntityManager.find method leading to MySQLIntegrityConstraintViolationException

當我執行EntityManager.find()將引發以下異常:

引起原因:com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:字段列表中的列“日期”不明確

我嘗試查找的類(配置文件)與另一個實體類(圖庫)具有雙向的一對一關系。 在理解why拋出此異常以及how解決該異常方面,我將不勝感激。 以下是兩個實體類:

public class Profile {
 ...
 private java.sql.Date date;
 private my.webapp.Gallery gallery;
 ...

 @OneToOne
 @JoinColumn(name="gallery_id")
 public my.webapp.Gallery getGallery() {
   return gallery
 }
 ...
}

public class Gallery {
 ...
 private my.webapp.Profile profile;
 ...

 @OneToOne(mappedBy="gallery")
 public my.webapp.Profile getProfile() {
   return profile
 }
 ...
} 

是不是因為“ date”是保留關鍵字? 嘗試將其添加到“ date”屬性(或getter)中。 它將引用屬性名稱。

@Column(name="`date`")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM