[hibernate-issues] [JIRA] (HHH-14072) PersistenceException for "More than one row with the given identifier was found" Not raised when expected

wafa (JIRA) jira at hibernate.atlassian.net
Sun Jun 14 21:28:57 EDT 2020


wafa ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ee6ae0a41f7000abb02fb3d ) *created* an issue

Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYTMwZmZjYmJlOTc1NDQ5ZjhlMmQ1NjdkMjE4NjcxYWUiLCJwIjoiaiJ9 ) / Bug ( https://hibernate.atlassian.net/browse/HHH-14072?atlOrigin=eyJpIjoiYTMwZmZjYmJlOTc1NDQ5ZjhlMmQ1NjdkMjE4NjcxYWUiLCJwIjoiaiJ9 ) HHH-14072 ( https://hibernate.atlassian.net/browse/HHH-14072?atlOrigin=eyJpIjoiYTMwZmZjYmJlOTc1NDQ5ZjhlMmQ1NjdkMjE4NjcxYWUiLCJwIjoiaiJ9 ) PersistenceException for "More than one row with the given identifier was found" Not raised when expected ( https://hibernate.atlassian.net/browse/HHH-14072?atlOrigin=eyJpIjoiYTMwZmZjYmJlOTc1NDQ5ZjhlMmQ1NjdkMjE4NjcxYWUiLCJwIjoiaiJ9 )

Issue Type: Bug Affects Versions: 5.4.0, 5.3.15 Assignee: Unassigned Components: hibernate-core Created: 14/Jun/2020 18:28 PM Labels: core hibernate Priority: Major Reporter: wafa ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ee6ae0a41f7000abb02fb3d )

For a OneToOne relationship, if the table associated with the owning side entity has 2 records related to the non-owning side entity, this should raise a PersistenceException, claiming that "More than one row with the given identifier was found", e.g.:

public class EntityA {
   @Id
   @GeneratedValue
   private Long id;

   @OneToOne(mappedBy = "entityA" )
   private EntityB entityB;
//...
}

public class EntityB {
   @Id
   @GeneratedValue
   private Long id;

   @OneToOne
   @JoinColumn(name = "ENTITY_A_ID" , referencedColumnName = "ID" )
   private EntityA entityA;

   @OneToMany(cascade = CascadeType.ALL, mappedBy = "entityB" , fetch = FetchType.EAGER)
   private List<EntityC> entityCS;
//...
}

If EntityB has an association of type ToMany with eager fetching, this will bypass the duplicated foreign key references check for the OneToOne association with entity A, and the Exception will not be thrown

>From The AbstractEntityOwner load method code, the exception will not be thrown if the Entity is a collection owner

if ( this.getCollectionOwners() != null ) {
           return list.get(0);
       } else {
           throw new HibernateException( "More than one row with the given identifier was found: " + id + ", for class: " + this.persister.getEntityName());
       }
//...

There is no check if different records from owning side entity references the same key of the non-owning side entity

( https://hibernate.atlassian.net/browse/HHH-14072#add-comment?atlOrigin=eyJpIjoiYTMwZmZjYmJlOTc1NDQ5ZjhlMmQ1NjdkMjE4NjcxYWUiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-14072#add-comment?atlOrigin=eyJpIjoiYTMwZmZjYmJlOTc1NDQ5ZjhlMmQ1NjdkMjE4NjcxYWUiLCJwIjoiaiJ9 )

Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8 ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100128- sha1:14a4bff )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20200615/c9b0b1cd/attachment.html 


More information about the hibernate-issues mailing list