99import jakarta .persistence .criteria .Join ;
1010import jakarta .persistence .criteria .JoinType ;
1111import jakarta .persistence .criteria .Root ;
12-
13- import org .hibernate .Session ;
12+ import org .hibernate .boot .model .naming .ImplicitNamingStrategy ;
1413import org .hibernate .boot .model .naming .ImplicitNamingStrategyJpaCompliantImpl ;
15- import org .hibernate .cfg .Configuration ;
16-
14+ import org .hibernate .cfg .AvailableSettings ;
15+ import org . hibernate . testing . orm . junit . DomainModel ;
1716import org .hibernate .testing .orm .junit .JiraKey ;
18- import org .hibernate .testing .junit4 .BaseCoreFunctionalTestCase ;
19- import org .junit .Test ;
17+ import org .hibernate .testing .orm .junit .ServiceRegistry ;
18+ import org .hibernate .testing .orm .junit .SessionFactory ;
19+ import org .hibernate .testing .orm .junit .SessionFactoryScope ;
20+ import org .hibernate .testing .orm .junit .SettingProvider ;
21+ import org .junit .jupiter .api .Test ;
2022
21- import static org .junit . Assert . assertEquals ;
23+ import static org .assertj . core . api . Assertions . assertThat ;
2224
2325/**
2426 * @author Emmanuel Bernard
2527 */
26- public class IdManyToOneTest extends BaseCoreFunctionalTestCase {
28+ @ DomainModel (
29+ annotatedClasses = {
30+ Store .class ,
31+ Customer .class ,
32+ StoreCustomer .class ,
33+ CardKey .class ,
34+ CardField .class ,
35+ Card .class ,
36+ Project .class ,
37+ Course .class ,
38+ Student .class ,
39+ CourseStudent .class ,
40+
41+ //tested only through deployment
42+ //ANN-590 testIdClassManyToOneWithReferenceColumn
43+ Customers .class ,
44+ ShoppingBaskets .class ,
45+ ShoppingBasketsPK .class ,
46+ BasketItems .class ,
47+ BasketItemsPK .class
48+ }
49+ )
50+ @ ServiceRegistry (
51+ settingProviders = @ SettingProvider (settingName = AvailableSettings .IMPLICIT_NAMING_STRATEGY ,
52+ provider = IdManyToOneTest .ImplicitNameSettingProvider .class )
53+ )
54+ @ SessionFactory
55+ public class IdManyToOneTest {
56+
57+ public static class ImplicitNameSettingProvider implements SettingProvider .Provider <ImplicitNamingStrategy > {
58+
59+ @ Override
60+ public ImplicitNamingStrategy getSetting () {
61+ return ImplicitNamingStrategyJpaCompliantImpl .INSTANCE ;
62+ }
63+ }
64+
2765 @ Test
28- public void testFkCreationOrdering () {
66+ public void testFkCreationOrdering (SessionFactoryScope scope ) {
2967 //no real test case, the sessionFactory building is tested
30- Session s = openSession ();
31- s .close ();
68+ scope .inTransaction (
69+ session -> {
70+ }
71+ );
3272 }
3373
3474 @ Test
35- public void testIdClassManyToOne () {
36- inTransaction ( s -> {
75+ public void testIdClassManyToOne (SessionFactoryScope scope ) {
76+ scope . inTransaction ( s -> {
3777 Store store = new Store ();
3878 Customer customer = new Customer ();
3979 s .persist ( store );
@@ -43,18 +83,19 @@ public void testIdClassManyToOne() {
4383 s .flush ();
4484 s .clear ();
4585
46- store = s .get ( Store .class , store .id );
47- assertEquals ( 1 , store .customers .size () );
48- assertEquals ( customer . id , store .customers .iterator ().next ().customer .id );
86+ store = s .find ( Store .class , store .id );
87+ assertThat ( store .customers .size () ). isEqualTo ( 1 );
88+ assertThat ( store .customers .iterator ().next ().customer . id ). isEqualTo ( customer .id );
4989 } );
5090 //TODO test Customers / ShoppingBaskets / BasketItems testIdClassManyToOneWithReferenceColumn
5191 }
5292
5393 @ Test
54- @ JiraKey ( value = "HHH-7767" )
55- public void testCriteriaRestrictionOnIdManyToOne () {
56- inTransaction ( s -> {
57- s .createQuery ( "from Course c join c.students cs join cs.student s where s.name = 'Foo'" , Object [].class ).list ();
94+ @ JiraKey (value = "HHH-7767" )
95+ public void testCriteriaRestrictionOnIdManyToOne (SessionFactoryScope scope ) {
96+ scope .inTransaction ( s -> {
97+ s .createQuery ( "from Course c join c.students cs join cs.student s where s.name = 'Foo'" , Object [].class )
98+ .list ();
5899
59100 CriteriaBuilder criteriaBuilder = s .getCriteriaBuilder ();
60101 CriteriaQuery <Course > criteria = criteriaBuilder .createQuery ( Course .class );
@@ -77,34 +118,4 @@ public void testCriteriaRestrictionOnIdManyToOne() {
77118// criteria2.list();
78119 } );
79120 }
80-
81- @ Override
82- protected Class [] getAnnotatedClasses () {
83- return new Class [] {
84- Store .class ,
85- Customer .class ,
86- StoreCustomer .class ,
87- CardKey .class ,
88- CardField .class ,
89- Card .class ,
90- Project .class ,
91- Course .class ,
92- Student .class ,
93- CourseStudent .class ,
94-
95- //tested only through deployment
96- //ANN-590 testIdClassManyToOneWithReferenceColumn
97- Customers .class ,
98- ShoppingBaskets .class ,
99- ShoppingBasketsPK .class ,
100- BasketItems .class ,
101- BasketItemsPK .class
102- };
103- }
104-
105- @ Override
106- protected void configure (Configuration configuration ) {
107- super .configure ( configuration );
108- configuration .setImplicitNamingStrategy ( ImplicitNamingStrategyJpaCompliantImpl .INSTANCE );
109- }
110121}
0 commit comments