【发布时间】:2017-05-13 05:24:05
【问题描述】:
org.hibernate.HibernateException: 找到多行具有给定标识符的行:578,对于类:com.hibernate.query.performance.persistence.model.Store
数据库中没有标识符为 578 的重复存储行。已使用 SQL 检查:
SELECT *
FROM store
WHERE store.store_id = 578;
它返回了 0 条记录。
One、Two 上的其他问题指出问题可能出在 OneToOne 映射本身。 Store 和 Staff 实体具有 OneToOne 关系,我的映射如下:
员工:
@OneToOne(mappedBy = "manager_staff", cascade = CascadeType.ALL, orphanRemoval = true)
public Store getStore() {
return store;
}
商店:
@OneToOne
@JoinColumn(name = "manager_staff_id", referencedColumnName = "staff_id", nullable = false)
public Staff getManager_staff() {
return manager_staff;
}
如何解决?
更新:
查询修改为:
Query query = session.createQuery("select c " +
" from Rental r, Customer c join fetch c.address address join fetch address.store store join fetch address.city city " +
" where r.customer = c " +
" and r.returnDate is null");
例外:
org.hibernate.HibernateException: More than one row with the given identifier was found: 2951, for class: com.hibernate.query.performance.persistence.model.Store
没有对数据库进行修改。我不确定 HQL 是否正确,因为 JProfiler 无法捕获任何 JPA/Hibernate 记录。唯一被捕获的指标是运行的 JDBC 连接。
【问题讨论】:
标签: java postgresql hibernate hql