org.hibernate.hibernateException:找到了带有给定标识符的一行以上:578,for类:com.hibernate.query.query.performance.permistence.model.model.store.store.store
数据库没有标识符578的重复存储行。它是使用SQL检查的:
SELECT *
FROM store
WHERE store.store_id = 578;
它返回了0个记录。
另一个问题,两个指出问题可能是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连接。
您的数据有故障,OneToOne
表示您必须具有链接 - 因此请确保查询返回一个记录。如果需要可选,则必须使其成为OneToMany