23
23
*/
24
24
package org .hibernate .jpa .test .lock ;
25
25
26
+ import static org .junit .Assert .assertEquals ;
27
+ import static org .junit .Assert .assertFalse ;
28
+ import static org .junit .Assert .assertNotNull ;
29
+ import static org .junit .Assert .assertNull ;
30
+ import static org .junit .Assert .assertTrue ;
31
+ import static org .junit .Assert .fail ;
32
+
26
33
import java .util .List ;
27
34
import java .util .Map ;
35
+
28
36
import javax .persistence .Entity ;
29
37
import javax .persistence .EntityManager ;
30
38
import javax .persistence .Id ;
31
39
import javax .persistence .LockModeType ;
32
40
import javax .persistence .Query ;
33
41
import javax .persistence .Table ;
34
42
35
- import org .hibernate .testing .TestForIssue ;
36
- import org .junit .Test ;
37
-
38
43
import org .hibernate .LockMode ;
44
+ import org .hibernate .internal .SessionImpl ;
39
45
import org .hibernate .jpa .AvailableSettings ;
40
46
import org .hibernate .jpa .QueryHints ;
41
47
import org .hibernate .jpa .internal .QueryImpl ;
42
48
import org .hibernate .jpa .test .BaseEntityManagerFunctionalTestCase ;
43
- import org .hibernate .internal .SessionImpl ;
44
-
45
- import static org .junit .Assert .assertEquals ;
46
- import static org .junit .Assert .assertFalse ;
47
- import static org .junit .Assert .assertNotNull ;
48
- import static org .junit .Assert .assertNull ;
49
- import static org .junit .Assert .assertTrue ;
50
- import static org .junit .Assert .fail ;
49
+ import org .hibernate .testing .TestForIssue ;
50
+ import org .junit .Test ;
51
51
52
52
/**
53
53
* @author Steve Ebersole
@@ -92,7 +92,7 @@ public void testOverallLockMode() {
92
92
93
93
@ Test
94
94
@ TestForIssue ( jiraKey = "HHH-8756" )
95
- public void testLockModeSetToNoneForNonSelectQueryShouldBeAllowed () {
95
+ public void testNoneLockModeForNonSelectQueryAllowed () {
96
96
EntityManager em = getOrCreateEntityManager ();
97
97
em .getTransaction ().begin ();
98
98
QueryImpl jpaQuery = em .createQuery ( "delete from Lockable l" ).unwrap ( QueryImpl .class );
@@ -103,24 +103,27 @@ public void testLockModeSetToNoneForNonSelectQueryShouldBeAllowed() {
103
103
jpaQuery .setLockMode ( LockModeType .NONE );
104
104
105
105
em .getTransaction ().commit ();
106
- em .close ();
107
- }
108
-
109
- @ Test ( expected = IllegalStateException .class )
110
- @ TestForIssue ( jiraKey = "HHH-8756" )
111
- public void testLockModeSetToValueOtherThanNoneForNonSelectQueryIsNotAllowed () {
112
- EntityManager em = getOrCreateEntityManager ();
106
+ em .clear ();
107
+
108
+ // ensure other modes still throw the exception
113
109
em .getTransaction ().begin ();
114
- QueryImpl jpaQuery = em .createQuery ( "delete from Lockable l" ).unwrap ( QueryImpl .class );
110
+ jpaQuery = em .createQuery ( "delete from Lockable l" ).unwrap ( QueryImpl .class );
115
111
116
- org . hibernate . internal . QueryImpl hqlQuery = (org .hibernate .internal .QueryImpl ) jpaQuery .getHibernateQuery ();
112
+ hqlQuery = (org .hibernate .internal .QueryImpl ) jpaQuery .getHibernateQuery ();
117
113
assertEquals ( LockMode .NONE , hqlQuery .getLockOptions ().getLockMode () );
118
114
119
- // Throws IllegalStateException
120
- jpaQuery .setLockMode ( LockModeType .PESSIMISTIC_WRITE );
121
-
122
- em .getTransaction ().commit ();
123
- em .close ();
115
+ try {
116
+ // Throws IllegalStateException
117
+ jpaQuery .setLockMode ( LockModeType .PESSIMISTIC_WRITE );
118
+ fail ( "IllegalStateException should have been thrown." );
119
+ }
120
+ catch (IllegalStateException e ) {
121
+ // expected
122
+ }
123
+ finally {
124
+ em .getTransaction ().rollback ();
125
+ em .close ();
126
+ }
124
127
}
125
128
126
129
@ Test
0 commit comments