Hibernate : More than one row with given identifier found

Viewed 20

I have an entity class.

@Entity
@Table(name = "Test")

public class TestEntity{
    @Id
    @Column(name = "test_id")
    private String testId;
}

Test table does not have any primary key, but due to @Entity I had to use @Id for testId column. testId column can have duplicate values.

When I save the records in the db it gives this error.

org.hibernate.HibernateException: More than one row with the given identifier was found: 353, for class: com.abc.xyz.TestEntity

I can not add any new column as a unique identifier in the table as there are millions of records in it already in production.

Tried the below solution but all failed. @Embeddable @ManyToOne

Please help me to solve this issue.

1 Answers

If you don't have a primary key column you don't really have entities and therefore you can't really use JPA.

Use JDBC instead. (Not Spring Data JDBC which would have you run into the same problem)

Related