|
4 | 4 | */ |
5 | 5 | package org.hibernate.orm.test.merge; |
6 | 6 |
|
7 | | -import org.hibernate.testing.orm.junit.JiraKey; |
8 | | -import org.junit.Before; |
9 | | -import org.junit.Test; |
10 | | - |
11 | 7 | import jakarta.persistence.CascadeType; |
12 | 8 | import jakarta.persistence.Entity; |
13 | 9 | import jakarta.persistence.FetchType; |
|
17 | 13 | import jakarta.persistence.JoinColumn; |
18 | 14 | import jakarta.persistence.ManyToOne; |
19 | 15 | import jakarta.persistence.OneToMany; |
| 16 | +import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; |
| 17 | +import org.hibernate.testing.orm.junit.JiraKey; |
| 18 | +import org.hibernate.testing.orm.junit.Jpa; |
| 19 | +import org.junit.jupiter.api.BeforeAll; |
| 20 | +import org.junit.jupiter.api.Test; |
| 21 | + |
20 | 22 | import java.util.ArrayList; |
21 | 23 | import java.util.List; |
22 | 24 |
|
23 | | -import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; |
24 | | - |
25 | 25 | /** |
26 | 26 | * @author Lisandro Fernandez (kelechul at gmail dot com) |
27 | 27 | */ |
28 | 28 | @JiraKey("HHH-13815") |
29 | | -public class BidirectionalOneToManyMergeTest extends org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase { |
30 | | - |
31 | | - @Override |
32 | | - protected Class<?>[] getAnnotatedClasses() { |
33 | | - return new Class<?>[]{ |
34 | | - Post.class, |
35 | | - PostComment.class, |
36 | | - }; |
37 | | - } |
| 29 | +@Jpa( |
| 30 | + annotatedClasses = { |
| 31 | + BidirectionalOneToManyMergeTest.Post.class, |
| 32 | + BidirectionalOneToManyMergeTest.PostComment.class, |
| 33 | + } |
| 34 | +) |
| 35 | +public class BidirectionalOneToManyMergeTest { |
| 36 | + |
38 | 37 |
|
39 | | - @Before |
40 | | - public void setUp() { |
41 | | - doInJPA(this::entityManagerFactory, entityManager -> { |
| 38 | + @BeforeAll |
| 39 | + public void setUp(EntityManagerFactoryScope scope) { |
| 40 | + scope.inTransaction( entityManager -> { |
42 | 41 | entityManager.persist( |
43 | | - new Post("High-Performance Java Persistence").setId(1L) |
| 42 | + new Post( "High-Performance Java Persistence" ).setId( 1L ) |
44 | 43 | ); |
45 | | - }); |
| 44 | + } ); |
46 | 45 | } |
47 | 46 |
|
48 | 47 | @Test |
49 | | - public void testMerge() { |
50 | | - doInJPA(this::entityManagerFactory, entityManager -> { |
51 | | - Post post = entityManager.find(Post.class, 1L); |
52 | | - post.addComment(new PostComment("This post rocks!", post)); |
| 48 | + public void testMerge(EntityManagerFactoryScope scope) { |
| 49 | + scope.inTransaction( entityManager -> { |
| 50 | + Post post = entityManager.find( Post.class, 1L ); |
| 51 | + post.addComment( new PostComment( "This post rocks!", post ) ); |
53 | 52 | post.getComments().isEmpty(); |
54 | | - entityManager.merge(post); |
55 | | - }); |
| 53 | + entityManager.merge( post ); |
| 54 | + } ); |
56 | 55 | } |
57 | 56 |
|
58 | 57 | @Entity |
@@ -101,15 +100,15 @@ private Post setComments(List<PostComment> comments) { |
101 | 100 | } |
102 | 101 |
|
103 | 102 | public Post addComment(PostComment comment) { |
104 | | - comments.add(comment); |
105 | | - comment.setPost(this); |
| 103 | + comments.add( comment ); |
| 104 | + comment.setPost( this ); |
106 | 105 |
|
107 | 106 | return this; |
108 | 107 | } |
109 | 108 |
|
110 | 109 | public Post removeComment(PostComment comment) { |
111 | | - comments.remove(comment); |
112 | | - comment.setPost(null); |
| 110 | + comments.remove( comment ); |
| 111 | + comment.setPost( null ); |
113 | 112 |
|
114 | 113 | return this; |
115 | 114 | } |
@@ -165,9 +164,13 @@ public PostComment setPost(Post post) { |
165 | 164 |
|
166 | 165 | @Override |
167 | 166 | public boolean equals(Object o) { |
168 | | - if (this == o) return true; |
169 | | - if (!(o instanceof PostComment)) return false; |
170 | | - return id != null && id.equals(((PostComment) o).getId()); |
| 167 | + if ( this == o ) { |
| 168 | + return true; |
| 169 | + } |
| 170 | + if ( !(o instanceof PostComment) ) { |
| 171 | + return false; |
| 172 | + } |
| 173 | + return id != null && id.equals( ((PostComment) o).getId() ); |
171 | 174 | } |
172 | 175 |
|
173 | 176 | @Override |
|
0 commit comments