Peter Raupp (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=630c5e1...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiODMwZWRjODU0...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-15469?atlOrigin=eyJpIjoiODMwZW...
) HHH-15469 (
https://hibernate.atlassian.net/browse/HHH-15469?atlOrigin=eyJpIjoiODMwZW...
) Missing EntityNotFoundException while using @ManyToOne / @OneToMany and EntityManager
interface (
https://hibernate.atlassian.net/browse/HHH-15469?atlOrigin=eyJpIjoiODMwZW...
)
Issue Type: Bug Affects Versions: 6.1.2 Assignee: Unassigned Components: hibernate-core
Created: 29/Aug/2022 01:00 AM Environment: Java 18, Windows 10, H2-InMemory-DB,
ORM Testcase sample see
https://github.com/PeRaVs/hibernate-sample (
https://github.com/PeRaVs/hibernate-sample ) Priority: Major Reporter: Peter Raupp (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=630c5e1...
)
When using Hibernate Session to remove a ManyToOne Child Entity, EntityNotFoundException
will raise up.
jakarta.persistence.EntityNotFoundException: deleted object would be re-saved by cascade
(remove deleted object from associations): [org.hibernate.bugs.entities.Entity2#2_1
]
at
org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:133)
at
org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:175)
at
org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:182)
at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1426)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1408)
at org.hibernate.bugs.ORMUnitTestCase.removeEntity2_1(ORMUnitTestCase.java:78)
If the EntityManager is used instead, *the exception will not be thrown*. Therefore the
Session.remove() call has no effect because the entity is saved again via cascading.
ORM Testcase sample based on hibernate-test-case-template can be found here:
https://github.com/PeRaVs/hibernate-sample (
https://github.com/PeRaVs/hibernate-sample )
Look at ORMUnitTestCase.java (based on Session class, with EntityNotFoundException raised
up)
Look at JPAUnitTestCase.java (based on EntityManager, without EntityNotFoundException)
(
https://hibernate.atlassian.net/browse/HHH-15469#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-15469#add-comment?atlOrigin=ey...
)
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....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100206- sha1:5148740 )