44 */
55package org .hibernate .orm .test .insertordering ;
66
7- import org .hibernate .cfg .Environment ;
8- import org .hibernate .testing .DialectChecks ;
9- import org .hibernate .testing .RequiresDialectFeature ;
10- import org .hibernate .testing .orm .junit .JiraKey ;
11- import org .hibernate .testing .junit4 .BaseNonConfigCoreFunctionalTestCase ;
12- import org .hibernate .testing .orm .jdbc .PreparedStatementSpyConnectionProvider ;
13- import org .junit .Test ;
14-
157import jakarta .persistence .CascadeType ;
168import jakarta .persistence .Column ;
179import jakarta .persistence .Entity ;
2012import jakarta .persistence .OneToMany ;
2113import jakarta .persistence .OneToOne ;
2214import jakarta .persistence .Table ;
15+ import org .hibernate .boot .registry .StandardServiceRegistry ;
16+ import org .hibernate .boot .registry .StandardServiceRegistryBuilder ;
17+ import org .hibernate .testing .orm .jdbc .PreparedStatementSpyConnectionProvider ;
18+ import org .hibernate .testing .orm .junit .DialectFeatureChecks ;
19+ import org .hibernate .testing .orm .junit .DomainModel ;
20+ import org .hibernate .testing .orm .junit .JiraKey ;
21+ import org .hibernate .testing .orm .junit .RequiresDialectFeature ;
22+ import org .hibernate .testing .orm .junit .ServiceRegistryFunctionalTesting ;
23+ import org .hibernate .testing .orm .junit .ServiceRegistryProducer ;
24+ import org .hibernate .testing .orm .junit .SessionFactory ;
25+ import org .hibernate .testing .orm .junit .SessionFactoryScope ;
26+ import org .junit .jupiter .api .AfterEach ;
27+ import org .junit .jupiter .api .Test ;
2328
24- import java .sql .SQLException ;
2529import java .util .HashSet ;
26- import java .util .Map ;
2730import java .util .Set ;
2831
29- import static org .hibernate .testing .transaction .TransactionUtil .doInHibernate ;
32+ import static org .hibernate .cfg .BatchSettings .ORDER_INSERTS ;
33+ import static org .hibernate .cfg .BatchSettings .ORDER_UPDATES ;
34+ import static org .hibernate .cfg .BatchSettings .STATEMENT_BATCH_SIZE ;
35+ import static org .hibernate .cfg .JdbcSettings .CONNECTION_PROVIDER ;
3036
37+ @ SuppressWarnings ("JUnitMalformedDeclaration" )
3138@ JiraKey (value = "HHH-16485" )
32- @ RequiresDialectFeature (DialectChecks .SupportsJdbcDriverProxying .class )
33- public class InsertOrderingCircularDependencyFalsePositiveTest extends BaseNonConfigCoreFunctionalTestCase {
34-
35- private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider ();
39+ @ RequiresDialectFeature (feature = DialectFeatureChecks .SupportsJdbcDriverProxying .class )
40+ @ ServiceRegistryFunctionalTesting
41+ @ DomainModel (annotatedClasses = {
42+ InsertOrderingCircularDependencyFalsePositiveTest .Wrapper .class ,
43+ InsertOrderingCircularDependencyFalsePositiveTest .Condition .class ,
44+ InsertOrderingCircularDependencyFalsePositiveTest .SimpleCondition .class ,
45+ InsertOrderingCircularDependencyFalsePositiveTest .Expression .class ,
46+ InsertOrderingCircularDependencyFalsePositiveTest .ConstantExpression .class ,
47+ InsertOrderingCircularDependencyFalsePositiveTest .Condition .class ,
48+ InsertOrderingCircularDependencyFalsePositiveTest .CompoundCondition .class ,
49+ })
50+ @ SessionFactory
51+ public class InsertOrderingCircularDependencyFalsePositiveTest implements ServiceRegistryProducer {
52+ private final PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider ();
3653
3754 @ Override
38- protected Class [] getAnnotatedClasses () {
39- return new Class []{
40- Wrapper .class ,
41- Condition .class ,
42- SimpleCondition .class ,
43- Expression .class ,
44- ConstantExpression .class ,
45- Condition .class ,
46- CompoundCondition .class ,
47- };
55+ public StandardServiceRegistry produceServiceRegistry (StandardServiceRegistryBuilder builder ) {
56+ return builder .applySetting ( ORDER_INSERTS , true )
57+ .applySetting ( ORDER_UPDATES , true )
58+ .applySetting ( STATEMENT_BATCH_SIZE , 50 )
59+ .applySetting ( CONNECTION_PROVIDER , connectionProvider )
60+ .build ();
4861 }
4962
50- @ Override
51- protected void addSettings (Map settings ) {
52- settings .put (Environment .ORDER_INSERTS , "true" );
53- settings .put (Environment .ORDER_UPDATES , "true" );
54- settings .put (Environment .STATEMENT_BATCH_SIZE , "50" );
55- settings .put (
56- org .hibernate .cfg .AvailableSettings .CONNECTION_PROVIDER ,
57- connectionProvider
58- );
59- }
60-
61- @ Override
62- public void releaseResources () {
63- super .releaseResources ();
63+ @ AfterEach
64+ void tearDown (SessionFactoryScope factoryScope ) {
65+ factoryScope .dropData ();
6466 connectionProvider .stop ();
6567 }
6668
67- @ Override
68- protected boolean rebuildSessionFactoryOnError () {
69- return false ;
70- }
71-
7269 @ Test
73- public void testBatching () throws SQLException {
74- doInHibernate ( this :: sessionFactory , session -> {
70+ public void testBatching (SessionFactoryScope factoryScope ) {
71+ factoryScope . inTransaction ( session -> {
7572 connectionProvider .clear ();
7673 // This should be persistable but currently reports that it might be circular
7774 session .persist (Wrapper .create ());
7875 });
7976 }
8077
78+ @ SuppressWarnings ({"unused" , "MismatchedQueryAndUpdateOfCollection" })
8179 @ Entity (name = "Wrapper" )
8280 public static class Wrapper {
8381 @ Id
@@ -136,6 +134,7 @@ public static abstract class Condition {
136134 public Condition () {
137135 }
138136 }
137+ @ SuppressWarnings ("unused" )
139138 @ Entity (name = "SimpleCondition" )
140139 public static class SimpleCondition extends Condition {
141140 @ OneToOne (cascade = CascadeType .ALL )
@@ -155,6 +154,7 @@ protected Expression() {
155154 }
156155
157156 }
157+ @ SuppressWarnings ("unused" )
158158 @ Entity (name = "ConstantExpression" )
159159 public static class ConstantExpression extends Expression {
160160 @ Column (name = "val" )
0 commit comments