Skip to content

Commit 95ea186

Browse files
committed
HHH-10989 : fix test case to work pre-5.2
(cherry picked from commit 6569161)
1 parent 6d358cd commit 95ea186

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/cascade/CascadeWithFkConstraintTestTask.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
*/
77
package org.hibernate.test.bytecode.enhancement.cascade;
88

9+
import org.hibernate.Session;
10+
import org.hibernate.Transaction;
911
import org.hibernate.cfg.Configuration;
1012
import org.hibernate.cfg.Environment;
1113
import org.hibernate.test.bytecode.enhancement.AbstractEnhancerTestTask;
1214
import org.junit.Assert;
1315

1416
import javax.persistence.Entity;
15-
import javax.persistence.EntityManager;
16-
import javax.persistence.EntityTransaction;
1717
import javax.persistence.Id;
1818
import javax.persistence.JoinColumn;
1919
import javax.persistence.OneToMany;
@@ -39,8 +39,8 @@ public void prepare() {
3939
super.prepare( cfg );
4040

4141
// Create garage, add 2 cars to garage
42-
EntityManager em = getFactory().createEntityManager();
43-
EntityTransaction tx = em.getTransaction();
42+
Session s = getFactory().openSession();
43+
Transaction tx = s.getTransaction();
4444
tx.begin();
4545

4646
Garage garage = new Garage();
@@ -49,12 +49,12 @@ public void prepare() {
4949
garage.insert( car1 );
5050
garage.insert( car2 );
5151

52-
em.persist( garage );
53-
em.persist( car1 );
54-
em.persist( car2 );
52+
s.persist( garage );
53+
s.persist( car1 );
54+
s.persist( car2 );
5555

5656
tx.commit();
57-
em.close();
57+
s.close();
5858

5959
garageId = garage.id;
6060
car1Id = car1.id;
@@ -65,33 +65,33 @@ public void execute() {
6565

6666
// Remove garage
6767

68-
EntityManager em = getFactory().createEntityManager();
69-
EntityTransaction tx = em.getTransaction();
68+
Session s = getFactory().openSession();
69+
Transaction tx = s.getTransaction();
7070
tx.begin();
7171

72-
Garage toRemoveGarage = em.find( Garage.class, garageId );
73-
em.remove( toRemoveGarage );
72+
Garage toRemoveGarage = s.get( Garage.class, garageId );
73+
s.delete( toRemoveGarage );
7474

7575
tx.commit();
76-
em.close();
76+
s.close();
7777

7878
// Check if there is no garage but cars are still present
7979

80-
EntityManager testEm = getFactory().createEntityManager();
81-
tx = testEm.getTransaction();
80+
Session testSession = getFactory().openSession();
81+
tx = testSession.getTransaction();
8282
tx.begin();
8383

84-
Garage foundGarage = testEm.find( Garage.class, garageId );
84+
Garage foundGarage = testSession.get( Garage.class, garageId );
8585
Assert.assertNull( foundGarage );
8686

87-
Car foundCar1 = testEm.find( Car.class, car1Id );
87+
Car foundCar1 = testSession.get( Car.class, car1Id );
8888
Assert.assertEquals( car1Id, foundCar1.id );
8989

90-
Car foundCar2 = testEm.find( Car.class, car2Id );
90+
Car foundCar2 = testSession.get( Car.class, car2Id );
9191
Assert.assertEquals( car2Id, foundCar2.id );
9292

9393
tx.commit();
94-
testEm.close();
94+
testSession.close();
9595

9696
}
9797

0 commit comments

Comments
 (0)