1
org.hibernate.HibernateException:找到多個具有給定標識符的行:578,對於類com.hibernate.query.performance.persistence .model.Storeorg.hibernate.HibernateException:找到了多於一行的給定標識符
的數據庫沒有重複的存儲與行標識符578使用SQL有人檢查:
SELECT *
FROM store
WHERE store.store_id = 578;
它返回0的記錄。
One,Two上的其他問題指出,該問題可能與OneToOne映射本身有關。店裏的工作人員實體具有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連接。