-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-14416 test cases for re-saving a deleted entity #3706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ffa4b3f
HHH-14416 test cases
karge-itestra 6c680de
HHH-14416 additional test showing issue with "existsInDatabase"
karge-itestra 889e061
HHH-14416 tests annotated
karge-itestra 39b18b2
Merge branch 'main' into HHH-14416
gavinking befffca
Update hibernate-core/src/test/java/org/hibernate/event/ReSaveReferen…
gavinking 3b0affb
Update hibernate-core/src/test/java/org/hibernate/event/ReSaveReferen…
gavinking cd767c3
Update hibernate-core/src/test/java/org/hibernate/event/ReSaveReferen…
gavinking 4126397
Update hibernate-core/src/test/java/org/hibernate/event/ReSaveReferen…
gavinking 4425ea0
Update hibernate-core/src/test/java/org/hibernate/event/ReSaveReferen…
gavinking 669d60f
Update hibernate-core/src/test/java/org/hibernate/event/ReSaveReferen…
gavinking 03cf943
Update hibernate-core/src/test/java/org/hibernate/event/ReSaveReferen…
gavinking e7dc900
Update hibernate-core/src/test/java/org/hibernate/event/ReSaveReferen…
gavinking File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
hibernate-core/src/test/java/org/hibernate/event/ReSaveReferencedDeletedEntity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package org.hibernate.event; | ||
|
|
||
| import org.hibernate.testing.TestForIssue; | ||
| import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; | ||
| import org.junit.Test; | ||
|
|
||
| import jakarta.persistence.*; | ||
|
|
||
| import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; | ||
|
|
||
| public class ReSaveReferencedDeletedEntity extends BaseCoreFunctionalTestCase { | ||
| @Override | ||
| protected Class<?>[] getAnnotatedClasses() { | ||
| return new Class<?>[] { Child.class, Parent.class }; | ||
| } | ||
|
|
||
| @Test | ||
| @TestForIssue(jiraKey = "HHH-14416") | ||
gavinking marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public void testReSaveDeletedEntityWithReferences() { | ||
| doInHibernate( this::sessionFactory, session -> { | ||
| Parent parent = new Parent(); | ||
|
|
||
| Child child = new Child(); | ||
| parent.setChild( child ); | ||
|
|
||
| session.saveOrUpdate( parent ); | ||
| session.saveOrUpdate( child ); | ||
|
|
||
| session.remove(child); | ||
|
|
||
| session.save(child); | ||
| } ); | ||
| } | ||
|
|
||
| @Test | ||
| @TestForIssue(jiraKey = "HHH-14416") | ||
gavinking marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public void testReSaveDeletedEntityWithReferences2() { | ||
| doInHibernate( this::sessionFactory, session -> { | ||
| Parent parent = new Parent(); | ||
|
|
||
| Child child = new Child(); | ||
| parent.setChild( child ); | ||
|
|
||
| session.saveOrUpdate( parent ); | ||
| session.saveOrUpdate( child ); | ||
|
|
||
| session.remove(child); | ||
|
|
||
| session.detach(child); | ||
|
|
||
| session.save(child); | ||
| } ); | ||
| } | ||
|
|
||
| @Entity(name = "Child") | ||
| public static class Child { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Integer id; | ||
|
|
||
| public Integer getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public void setId(Integer id) { | ||
| this.id = id; | ||
| } | ||
| } | ||
|
|
||
| @Entity(name = "Parent") | ||
| public static class Parent { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Integer id; | ||
|
|
||
| @OneToOne(cascade = CascadeType.ALL) | ||
| private Child child; | ||
|
|
||
| public Integer getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public void setId(Integer id) { | ||
| this.id = id; | ||
| } | ||
|
|
||
| public Child getChild() { | ||
| return child; | ||
| } | ||
|
|
||
| public void setChild(Child child) { | ||
| this.child = child; | ||
| } | ||
| } | ||
| } | ||
100 changes: 100 additions & 0 deletions
100
hibernate-core/src/test/java/org/hibernate/event/ReSaveReferencedDeletedEntityJPA.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| package org.hibernate.event; | ||
|
|
||
| import org.hibernate.Session; | ||
| import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; | ||
| import org.hibernate.testing.orm.junit.JiraKey; | ||
| import org.junit.Test; | ||
|
|
||
| import jakarta.persistence.*; | ||
|
|
||
| public class ReSaveReferencedDeletedEntityJPA extends BaseEntityManagerFunctionalTestCase { | ||
| @Override | ||
| protected Class<?>[] getAnnotatedClasses() { | ||
| return new Class<?>[] { Child.class, Parent.class }; | ||
| } | ||
|
|
||
| @Test | ||
| @ JiraKey("HHH-14416") | ||
| public void testRefreshUnDeletedEntityWithReferencesJPA() { | ||
| EntityManager em = getOrCreateEntityManager(); | ||
| em.getTransaction().begin(); | ||
|
|
||
| Parent parent = new Parent(); | ||
| parent.setId(1); | ||
|
|
||
| Child child = new Child(); | ||
| child.setId(2); | ||
| parent.setChild( child ); | ||
|
|
||
| em.unwrap(Session.class).save( parent ); | ||
|
|
||
| em.flush(); | ||
|
|
||
| em.remove( parent ); | ||
|
|
||
| em.detach( parent ); | ||
|
|
||
| em.persist( parent ); | ||
|
|
||
| em.refresh( child ); | ||
| } | ||
|
|
||
| @Test | ||
| @JiraKey("HHH-14416") | ||
| public void testReSaveDeletedEntityWithReferencesJPA() { | ||
| EntityManager em = getOrCreateEntityManager(); | ||
| em.getTransaction().begin(); | ||
|
|
||
| Parent parent = new Parent(); | ||
| parent.setId(1); | ||
|
|
||
| Child child = new Child(); | ||
| child.setId(2); | ||
| parent.setChild( child ); | ||
|
|
||
| em.persist( parent ); | ||
|
|
||
| em.remove( child ); | ||
|
|
||
| em.unwrap(Session.class).save( child ); | ||
| } | ||
|
|
||
| @Entity(name = "Child") | ||
| public static class Child { | ||
| @Id | ||
| private Integer id; | ||
|
|
||
| public Integer getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public void setId(Integer id) { | ||
| this.id = id; | ||
| } | ||
| } | ||
|
|
||
| @Entity(name = "Parent") | ||
| public static class Parent { | ||
| @Id | ||
| private Integer id; | ||
|
|
||
| @OneToOne(cascade = CascadeType.ALL) | ||
| private Child child; | ||
|
|
||
| public Integer getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public void setId(Integer id) { | ||
| this.id = id; | ||
| } | ||
|
|
||
| public Child getChild() { | ||
| return child; | ||
| } | ||
|
|
||
| public void setChild(Child child) { | ||
| this.child = child; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.