Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java org.hibernate.HibernateException:找到多个具有给定标识符的行_Java_Postgresql_Hibernate_Hql - Fatal编程技术网

Java org.hibernate.HibernateException:找到多个具有给定标识符的行

Java org.hibernate.HibernateException:找到多个具有给定标识符的行,java,postgresql,hibernate,hql,Java,Postgresql,Hibernate,Hql,org.hibernate.HibernateException:找到多个具有给定标识符的行:578,用于类:com.hibernate.query.performance.persistence.model.Store 数据库没有标识符为578的重复存储行。已使用SQL对其进行检查: SELECT * FROM store WHERE store.store_id = 578; 它返回了0条记录 关于的其他问题指出,问题可能与OneTONE映射本身有关。门店和员工实体之间有OneToOne

org.hibernate.HibernateException:找到多个具有给定标识符的行:578,用于类:com.hibernate.query.performance.persistence.model.Store

数据库没有标识符为578的重复存储行。已使用SQL对其进行检查:

SELECT * 
FROM store
WHERE store.store_id = 578;
它返回了0条记录

关于的其他问题指出,问题可能与OneTONE映射本身有关。门店和员工实体之间有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;
    }
商店:

@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”