|
25 | 25 | import jakarta.persistence.Table; |
26 | 26 |
|
27 | 27 | import org.hibernate.graph.GraphSemantic; |
28 | | -import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; |
29 | 28 |
|
| 29 | +import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; |
30 | 30 | import org.hibernate.testing.orm.junit.JiraKey; |
31 | | -import org.junit.Before; |
32 | | -import org.junit.Test; |
| 31 | +import org.hibernate.testing.orm.junit.Jpa; |
| 32 | +import org.junit.jupiter.api.BeforeEach; |
| 33 | +import org.junit.jupiter.api.Test; |
33 | 34 |
|
34 | 35 | import static org.assertj.core.api.Assertions.assertThat; |
35 | | -import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; |
36 | | - |
37 | 36 |
|
38 | 37 | /** |
39 | 38 | * @author Benjamin M. |
40 | 39 | * @author Nathan Xu |
41 | 40 | */ |
42 | 41 | @JiraKey( value = "HHH-14113" ) |
43 | 42 | @SuppressWarnings({ "unchecked", "rawtypes" }) |
44 | | -public class EntityGraphAttributeResolutionTest extends BaseEntityManagerFunctionalTestCase { |
| 43 | +@Jpa(annotatedClasses = {EntityGraphAttributeResolutionTest.User.class, EntityGraphAttributeResolutionTest.Group.class}) |
| 44 | +public class EntityGraphAttributeResolutionTest { |
45 | 45 |
|
46 | 46 | private User u; |
47 | 47 | private Group g1, g2; |
48 | 48 |
|
49 | | - @Override |
50 | | - protected Class<?>[] getAnnotatedClasses() { |
51 | | - return new Class<?>[] { User.class, Group.class }; |
52 | | - } |
53 | | - |
54 | | - @Before |
55 | | - public void setUp() { |
56 | | - doInJPA( this::entityManagerFactory, em -> { |
| 49 | + @BeforeEach |
| 50 | + public void setUp(EntityManagerFactoryScope scope) { |
| 51 | + scope.inTransaction( entityManager -> { |
57 | 52 | g1 = new Group(); |
58 | 53 | g1.addPermission( Permission.BAR ); |
59 | | - em.persist( g1 ); |
| 54 | + entityManager.persist( g1 ); |
60 | 55 |
|
61 | 56 | g2 = new Group(); |
62 | 57 | g2.addPermission( Permission.BAZ ); |
63 | | - em.persist( g2 ); |
| 58 | + entityManager.persist( g2 ); |
64 | 59 |
|
65 | 60 | u = new User(); |
66 | | - em.persist( u ); |
| 61 | + entityManager.persist( u ); |
67 | 62 | u.addGroup( g1 ); |
68 | 63 | u.addGroup( g2 ); |
69 | 64 | } ); |
70 | 65 | } |
71 | 66 |
|
72 | 67 | @Test |
73 | | - public void fetchAssocWithNamedFetchGraph() { |
74 | | - doInJPA( this::entityManagerFactory, em -> { |
75 | | - List result = em.createQuery( "SELECT u.groups FROM User u WHERE u.id = ?1" ) |
| 68 | + public void fetchAssocWithNamedFetchGraph(EntityManagerFactoryScope scope) { |
| 69 | + scope.inTransaction( entityManager -> { |
| 70 | + List result = entityManager.createQuery( "SELECT u.groups FROM User u WHERE u.id = ?1" ) |
76 | 71 | .setParameter(1, u.getId() ) |
77 | | - .setHint( GraphSemantic.FETCH.getJpaHintName(), em.getEntityGraph( Group.ENTITY_GRAPH ) ) |
| 72 | + .setHint( GraphSemantic.FETCH.getJpaHintName(), entityManager.getEntityGraph( Group.ENTITY_GRAPH ) ) |
78 | 73 | .getResultList(); |
79 | 74 |
|
80 | 75 | assertThat( result ).containsExactlyInAnyOrder( g1, g2 ); |
81 | 76 | } ); |
82 | 77 | } |
83 | 78 |
|
84 | 79 | @Test |
85 | | - public void fetchAssocWithNamedFetchGraphAndJoin() { |
86 | | - doInJPA( this::entityManagerFactory, em -> { |
87 | | - List result = em.createQuery( "SELECT g FROM User u JOIN u.groups g WHERE u.id = ?1" ) |
| 80 | + public void fetchAssocWithNamedFetchGraphAndJoin(EntityManagerFactoryScope scope) { |
| 81 | + scope.inTransaction( entityManager -> { |
| 82 | + List result = entityManager.createQuery( "SELECT g FROM User u JOIN u.groups g WHERE u.id = ?1" ) |
88 | 83 | .setParameter( 1, u.getId() ) |
89 | | - .setHint( GraphSemantic.FETCH.getJpaHintName(), em.getEntityGraph( Group.ENTITY_GRAPH ) ) |
| 84 | + .setHint( GraphSemantic.FETCH.getJpaHintName(), entityManager.getEntityGraph( Group.ENTITY_GRAPH ) ) |
90 | 85 | .getResultList(); |
91 | 86 |
|
92 | 87 | assertThat( result ).containsExactlyInAnyOrder( g1, g2 ); |
93 | 88 | } ); |
94 | 89 | } |
95 | 90 |
|
96 | 91 | @Test |
97 | | - public void fetchAssocWithAdhocFetchGraph() { |
98 | | - doInJPA( this::entityManagerFactory, em -> { |
99 | | - EntityGraph<Group> eg = em.createEntityGraph( Group.class ); |
| 92 | + public void fetchAssocWithAdhocFetchGraph(EntityManagerFactoryScope scope) { |
| 93 | + scope.inTransaction( entityManager -> { |
| 94 | + EntityGraph<Group> eg = entityManager.createEntityGraph( Group.class ); |
100 | 95 | eg.addAttributeNodes( "permissions" ); |
101 | 96 |
|
102 | | - List result = em.createQuery( "SELECT u.groups FROM User u WHERE u.id = ?1" ) |
| 97 | + List result = entityManager.createQuery( "SELECT u.groups FROM User u WHERE u.id = ?1" ) |
103 | 98 | .setParameter(1, u.getId() ) |
104 | 99 | .setHint( GraphSemantic.FETCH.getJpaHintName(), eg ) |
105 | 100 | .getResultList(); |
|
0 commit comments