77import java .util .ArrayList ;
88import java .util .Arrays ;
99import java .util .List ;
10- import java .util .Map ;
10+
11+ import org .hibernate .cfg .AvailableSettings ;
12+ import org .hibernate .envers .AuditJoinTable ;
13+ import org .hibernate .envers .AuditReaderFactory ;
14+ import org .hibernate .envers .Audited ;
15+
16+ import org .hibernate .testing .envers .junit .EnversTest ;
17+ import org .hibernate .testing .jta .TestingJtaBootstrap ;
18+ import org .hibernate .testing .jta .TestingJtaPlatformImpl ;
19+ import org .hibernate .testing .orm .junit .BeforeClassTemplate ;
20+ import org .hibernate .testing .orm .junit .DialectFeatureChecks ;
21+ import org .hibernate .testing .orm .junit .EntityManagerFactoryScope ;
22+ import org .hibernate .testing .orm .junit .JiraKey ;
23+ import org .hibernate .testing .orm .junit .Jpa ;
24+ import org .hibernate .testing .orm .junit .RequiresDialectFeature ;
25+ import org .hibernate .testing .orm .junit .Setting ;
26+ import org .hibernate .testing .orm .junit .SettingConfiguration ;
27+ import org .junit .jupiter .api .Test ;
1128
1229import jakarta .persistence .CascadeType ;
1330import jakarta .persistence .Entity ;
14- import jakarta .persistence .EntityManager ;
1531import jakarta .persistence .FetchType ;
1632import jakarta .persistence .GeneratedValue ;
1733import jakarta .persistence .GenerationType ;
2036import jakarta .persistence .ManyToOne ;
2137import jakarta .persistence .OneToMany ;
2238
23- import org .hibernate .cfg .AvailableSettings ;
24- import org .hibernate .envers .AuditJoinTable ;
25- import org .hibernate .envers .Audited ;
26- import org .hibernate .orm .test .envers .BaseEnversJPAFunctionalTestCase ;
27- import org .hibernate .orm .test .envers .Priority ;
28- import org .junit .Test ;
29-
30- import org .hibernate .testing .DialectChecks ;
31- import org .hibernate .testing .RequiresDialectFeature ;
32- import org .hibernate .testing .orm .junit .JiraKey ;
33- import org .hibernate .testing .jta .TestingJtaBootstrap ;
34- import org .hibernate .testing .jta .TestingJtaPlatformImpl ;
35-
36- import static org .junit .Assert .assertEquals ;
39+ import static org .junit .jupiter .api .Assertions .assertEquals ;
3740
3841/**
3942 * @author Chris Cranford
4043 */
41- @ JiraKey (value ="HHH-13191" )
42- @ RequiresDialectFeature ({ DialectChecks .SupportsNoColumnInsert .class , DialectChecks .SupportsIdentityColumns .class })
43- public class IdentifierProxyJtaSessionClosedBeforeCommitTest extends BaseEnversJPAFunctionalTestCase {
44- @ Override
45- protected Class <?>[] getAnnotatedClasses () {
46- return new Class <?>[] { AuthUser .class , AuthClient .class };
47- }
48-
49- @ Override
50- protected void addConfigOptions (Map options ) {
51- TestingJtaBootstrap .prepare ( options );
52- options .put ( AvailableSettings .ALLOW_JTA_TRANSACTION_ACCESS , "true" );
53-
54- // NOTE: This option is critical in order for the problem to be reproducable.
55- // If this option is not set to 'true', then the failure condition does not happen.
56- options .put ( AvailableSettings .JPA_PROXY_COMPLIANCE , "true" );
57- }
58-
44+ @ JiraKey (value = "HHH-13191" )
45+ @ RequiresDialectFeature (feature = DialectFeatureChecks .SupportsNoColumnInsert .class )
46+ @ RequiresDialectFeature (feature = DialectFeatureChecks .SupportsIdentityColumns .class )
47+ @ EnversTest
48+ @ Jpa (
49+ annotatedClasses = {
50+ IdentifierProxyJtaSessionClosedBeforeCommitTest .AuthUser .class ,
51+ IdentifierProxyJtaSessionClosedBeforeCommitTest .AuthClient .class
52+ },
53+ integrationSettings = {
54+ @ Setting (name = AvailableSettings .ALLOW_JTA_TRANSACTION_ACCESS , value = "true" ),
55+ @ Setting (name = AvailableSettings .JPA_PROXY_COMPLIANCE , value = "true" )
56+ },
57+ settingConfigurations = @ SettingConfiguration (configurer = TestingJtaBootstrap .class )
58+ )
59+ public class IdentifierProxyJtaSessionClosedBeforeCommitTest {
5960 private Integer authUserId ;
6061 private Integer authClientId ;
6162
62- @ Test
63- @ Priority (10 )
64- public void initData () throws Exception {
63+ @ BeforeClassTemplate
64+ public void initData (EntityManagerFactoryScope scope ) throws Exception {
6565 // Revision 1
6666 TestingJtaPlatformImpl .INSTANCE .getTransactionManager ().begin ();
67- EntityManager entityManager = getEntityManager ();
67+ var entityManager = scope . getEntityManagerFactory (). createEntityManager ();
6868 try {
6969 final AuthUser authUser = new AuthUser ();
7070 final AuthClient authClient = new AuthClient ();
@@ -84,7 +84,7 @@ public void initData() throws Exception {
8484
8585 // Revision 2
8686 TestingJtaPlatformImpl .INSTANCE .getTransactionManager ().begin ();
87- entityManager = getEntityManager ();
87+ entityManager = scope . getEntityManagerFactory (). createEntityManager ();
8888 try {
8989 final AuthUser authUser = entityManager .find ( AuthUser .class , authUserId );
9090 authUser .setSomeValue ( "test" );
@@ -97,8 +97,11 @@ public void initData() throws Exception {
9797 }
9898
9999 @ Test
100- public void testRevisionCounts () {
101- assertEquals ( Arrays .asList ( 1 , 2 ), getAuditReader ().getRevisions ( AuthUser .class , authUserId ) );
100+ public void testRevisionCounts (EntityManagerFactoryScope scope ) {
101+ scope .inEntityManager ( entityManager -> assertEquals (
102+ Arrays .asList ( 1 , 2 ),
103+ AuditReaderFactory .get ( entityManager ).getRevisions ( AuthUser .class , authUserId )
104+ ) );
102105 }
103106
104107 @ Entity (name = "AuthUser" )
@@ -111,7 +114,7 @@ public static class AuthUser {
111114 private String someValue ;
112115
113116 @ ManyToOne (fetch = FetchType .LAZY )
114- @ JoinColumn (name = "idclient" , insertable = false , updatable = false )
117+ @ JoinColumn (name = "idclient" , insertable = false , updatable = false )
115118 private AuthClient authClient ;
116119
117120 public AuthUser () {
0 commit comments