【发布时间】:2010-12-17 23:55:16
【问题描述】:
当我执行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是 MySQL 中的保留关键字。看起来 Hibernate/JPA 没有逃脱它(我想知道为什么不)。开启 SQL 日志,验证生成的 SQL 是否正确。
标签: java mysql hibernate jpa ambiguous