@@ -22,54 +22,64 @@ public class PessimisticLockScopesIntegrationTest {
2222 EntityManagerFactory entityManagerFactory ;
2323
2424 @ Test
25- public void givenEclipseEntityWithJoinInheritance_whenNormalLock_thenShouldChildAndParentEntity () {
25+ public void givenEntityWithJoinInheritance_whenLock_thenNormalAndExtendScopesLockParentAndChildEntity () {
2626 EntityManager em = getEntityManagerWithOpenTransaction ();
27- Employee employee = new Employee (1L , "A " , "B " , new BigDecimal (4.5 ));
27+ Employee employee = new Employee (1L , "JOE " , "DOE " , new BigDecimal (4.5 ));
2828 em .persist (employee );
2929 em .getTransaction ()
3030 .commit ();
3131 em .close ();
3232
3333 // NORMAL SCOPE
34- em = getEntityManagerWithOpenTransaction ();
35- Employee foundEmployee = em .find (Employee .class , 1L , LockModeType .PESSIMISTIC_WRITE );
36- em .getTransaction ()
34+ EntityManager em2 = getEntityManagerWithOpenTransaction ();
35+ Employee foundEmployee = em2 .find (Employee .class , 1L , LockModeType .PESSIMISTIC_WRITE );
36+ em2 .getTransaction ()
3737 .rollback ();
3838
3939 // EXTENDED SCOPE
4040 Map <String , Object > map = new HashMap <>();
4141 map .put ("javax.persistence.lock.scope" , PessimisticLockScope .EXTENDED );
4242
43- em = getEntityManagerWithOpenTransaction ();
44- foundEmployee = em .find (Employee .class , 1L , LockModeType .PESSIMISTIC_WRITE , map );
43+ EntityManager em3 = getEntityManagerWithOpenTransaction ();
44+ foundEmployee = em3 .find (Employee .class , 1L , LockModeType .PESSIMISTIC_WRITE , map );
45+ em3 .getTransaction ()
46+ .rollback ();
47+
48+ em2 .close ();
49+ em3 .close ();
4550 }
4651
4752 @ Test
48- public void givenEclipseEntityWithElementCollection_whenNormalLock_thenShouldLockOnlyOwningEntity () {
53+ public void givenEntityWithElementCollection_whenLock_thenExtendScopeLocksAlsoCollectionTable () {
4954 EntityManager em = getEntityManagerWithOpenTransaction ();
5055 Address address = new Address ("Poland" , "Warsaw" );
51- Customer customer = new Customer (1L , "A " , "B " , Arrays .asList (address ));
56+ Customer customer = new Customer (1L , "JOHN " , "SMITH " , Arrays .asList (address ));
5257 em .persist (customer );
5358 em .getTransaction ()
5459 .commit ();
5560 em .close ();
5661
5762 // NORMAL SCOPE
58- em = getEntityManagerWithOpenTransaction ();
59- Customer foundCustomer = em .find (Customer .class , 1L , LockModeType .PESSIMISTIC_WRITE );
60- em .getTransaction ()
63+ EntityManager em2 = getEntityManagerWithOpenTransaction ();
64+ Customer foundCustomer = em2 .find (Customer .class , 1L , LockModeType .PESSIMISTIC_WRITE );
65+ em2 .getTransaction ()
6166 .rollback ();
6267
6368 // EXTENDED SCOPE
6469 Map <String , Object > map = new HashMap <>();
6570 map .put ("javax.persistence.lock.scope" , PessimisticLockScope .EXTENDED );
6671
67- em = getEntityManagerWithOpenTransaction ();
68- foundCustomer = em .find (Customer .class , 1L , LockModeType .PESSIMISTIC_WRITE , map );
72+ EntityManager em3 = getEntityManagerWithOpenTransaction ();
73+ foundCustomer = em3 .find (Customer .class , 1L , LockModeType .PESSIMISTIC_WRITE , map );
74+ em3 .getTransaction ()
75+ .rollback ();
76+
77+ em2 .close ();
78+ em3 .close ();
6979 }
7080
7181 @ Test
72- public void givenEclipseEntityWithOneToMany_whenNormalLock_thenShouldLockOnlyOwningEntity () {
82+ public void givenEclipseEntityWithOneToMany_whenLock_thenExtendedLockAlsoJoinTable () {
7383 EntityManager em = getEntityManagerWithOpenTransaction ();
7484 Student student = new Student (1L , "JOE" );
7585 Course course = new Course (1L , "COURSE" , student );
@@ -81,17 +91,22 @@ public void givenEclipseEntityWithOneToMany_whenNormalLock_thenShouldLockOnlyOwn
8191 em .close ();
8292
8393 // NORMAL SCOPE
84- em = getEntityManagerWithOpenTransaction ();
85- Course foundCourse = em .find (Course .class , 1L , LockModeType .PESSIMISTIC_WRITE );
86- em .getTransaction ()
94+ EntityManager em2 = getEntityManagerWithOpenTransaction ();
95+ Course foundCourse = em2 .find (Course .class , 1L , LockModeType .PESSIMISTIC_WRITE );
96+ em2 .getTransaction ()
8797 .rollback ();
8898
8999 // EXTENDED SCOPE
90100 Map <String , Object > map = new HashMap <>();
91101 map .put ("javax.persistence.lock.scope" , PessimisticLockScope .EXTENDED );
92102
93- em = getEntityManagerWithOpenTransaction ();
94- foundCourse = em .find (Course .class , 1L , LockModeType .PESSIMISTIC_WRITE , map );
103+ EntityManager em3 = getEntityManagerWithOpenTransaction ();
104+ foundCourse = em3 .find (Course .class , 1L , LockModeType .PESSIMISTIC_WRITE , map );
105+ em3 .getTransaction ()
106+ .rollback ();
107+
108+ em2 .close ();
109+ em3 .close ();
95110 }
96111
97112 protected EntityManager getEntityManagerWithOpenTransaction () {
0 commit comments