1

org.hibernate.HibernateException: More than one row with the given identifier was found: 578, for class: com.hibernate.query.performance.persistence.model.Store

The database does not have duplicate Store rows with identifier 578. It was checked using SQL:

SELECT * 
FROM store
WHERE store.store_id = 578;

It returned 0 records.

The other questions on One, Two pointed that the issue might be with OneToOne mapping itself. The Store and Staff entities have OneToOne relationship and mine are mapped like that:

Staff:

@OneToOne(mappedBy = "manager_staff", cascade = CascadeType.ALL, orphanRemoval = true)
    public Store getStore() {
        return store;
    }

Store:

@OneToOne
    @JoinColumn(name = "manager_staff_id", referencedColumnName = "staff_id", nullable = false)
    public Staff getManager_staff() {
        return manager_staff;
    }

How to fix it?


Update:

The exception changed a bit when the query was modified as:

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");

Exception:

org.hibernate.HibernateException: More than one row with the given identifier was found: 2951, for class: com.hibernate.query.performance.persistence.model.Store

There were no modifications to database. I am not sure if the HQL is correct since JProfiler cannot catch any JPA/Hibernate records. The only metrics being caught is JDBC connections that ran.

Community
  • 1
  • 1
J.Olufsen
  • 13,415
  • 44
  • 120
  • 185

1 Answers1

-1

Your data is faulty, OneToOne means you have to have the link - so make sure the query returns one record. If it needs to be optional you have to make it OneToMany

J.Olufsen
  • 13,415
  • 44
  • 120
  • 185
serge
  • 1,590
  • 2
  • 26
  • 49