6
6
*/
7
7
package org .hibernate .test .bytecode .enhancement .cascade ;
8
8
9
+ import org .hibernate .Session ;
10
+ import org .hibernate .Transaction ;
9
11
import org .hibernate .cfg .Configuration ;
10
12
import org .hibernate .cfg .Environment ;
11
13
import org .hibernate .test .bytecode .enhancement .AbstractEnhancerTestTask ;
12
14
import org .junit .Assert ;
13
15
14
16
import javax .persistence .Entity ;
15
- import javax .persistence .EntityManager ;
16
- import javax .persistence .EntityTransaction ;
17
17
import javax .persistence .Id ;
18
18
import javax .persistence .JoinColumn ;
19
19
import javax .persistence .OneToMany ;
@@ -39,8 +39,8 @@ public void prepare() {
39
39
super .prepare ( cfg );
40
40
41
41
// 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 ();
44
44
tx .begin ();
45
45
46
46
Garage garage = new Garage ();
@@ -49,12 +49,12 @@ public void prepare() {
49
49
garage .insert ( car1 );
50
50
garage .insert ( car2 );
51
51
52
- em .persist ( garage );
53
- em .persist ( car1 );
54
- em .persist ( car2 );
52
+ s .persist ( garage );
53
+ s .persist ( car1 );
54
+ s .persist ( car2 );
55
55
56
56
tx .commit ();
57
- em .close ();
57
+ s .close ();
58
58
59
59
garageId = garage .id ;
60
60
car1Id = car1 .id ;
@@ -65,33 +65,33 @@ public void execute() {
65
65
66
66
// Remove garage
67
67
68
- EntityManager em = getFactory ().createEntityManager ();
69
- EntityTransaction tx = em .getTransaction ();
68
+ Session s = getFactory ().openSession ();
69
+ Transaction tx = s .getTransaction ();
70
70
tx .begin ();
71
71
72
- Garage toRemoveGarage = em . find ( Garage .class , garageId );
73
- em . remove ( toRemoveGarage );
72
+ Garage toRemoveGarage = s . get ( Garage .class , garageId );
73
+ s . delete ( toRemoveGarage );
74
74
75
75
tx .commit ();
76
- em .close ();
76
+ s .close ();
77
77
78
78
// Check if there is no garage but cars are still present
79
79
80
- EntityManager testEm = getFactory ().createEntityManager ();
81
- tx = testEm .getTransaction ();
80
+ Session testSession = getFactory ().openSession ();
81
+ tx = testSession .getTransaction ();
82
82
tx .begin ();
83
83
84
- Garage foundGarage = testEm . find ( Garage .class , garageId );
84
+ Garage foundGarage = testSession . get ( Garage .class , garageId );
85
85
Assert .assertNull ( foundGarage );
86
86
87
- Car foundCar1 = testEm . find ( Car .class , car1Id );
87
+ Car foundCar1 = testSession . get ( Car .class , car1Id );
88
88
Assert .assertEquals ( car1Id , foundCar1 .id );
89
89
90
- Car foundCar2 = testEm . find ( Car .class , car2Id );
90
+ Car foundCar2 = testSession . get ( Car .class , car2Id );
91
91
Assert .assertEquals ( car2Id , foundCar2 .id );
92
92
93
93
tx .commit ();
94
- testEm .close ();
94
+ testSession .close ();
95
95
96
96
}
97
97
0 commit comments