File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
hibernate-core/src/test/java/org/hibernate/orm/test/query/resultmapping Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 17
17
import java .util .List ;
18
18
import java .util .Set ;
19
19
20
+ import jakarta .persistence .LockModeType ;
20
21
import org .hibernate .cfg .AvailableSettings ;
21
22
import org .hibernate .query .named .NamedResultSetMappingMemento ;
22
23
@@ -119,6 +120,29 @@ public void testImplicitAttributeMapping(SessionFactoryScope scope) {
119
120
);
120
121
}
121
122
123
+ @ Test
124
+ public void testImplicitAttributeMappingWithLockMode (SessionFactoryScope scope ) {
125
+ scope .inTransaction (
126
+ session -> {
127
+ // make sure it is in the repository
128
+ final NamedResultSetMappingMemento mappingMemento = session .getSessionFactory ()
129
+ .getQueryEngine ()
130
+ .getNamedObjectRepository ()
131
+ .getResultSetMappingMemento (
132
+ "entity-lockmode" );
133
+ assertThat ( mappingMemento , notNullValue () );
134
+
135
+ // apply it to a native-query
136
+ final String qryString = "select id, name, notes from SimpleEntityWithNamedMappings for update" ;
137
+ final List <SimpleEntityWithNamedMappings > results = session
138
+ .createNativeQuery ( qryString , "entity-lockmode" )
139
+ .list ();
140
+ assertThat ( results .size (), is ( 1 ) );
141
+ assertThat ( session .getLockMode (results .get (0 )), is (LockModeType .PESSIMISTIC_WRITE ));
142
+ }
143
+ );
144
+ }
145
+
122
146
@ Test
123
147
public void testMixedAttributeMapping (SessionFactoryScope scope ) {
124
148
scope .inTransaction (
Original file line number Diff line number Diff line change 14
14
import jakarta .persistence .FetchType ;
15
15
import jakarta .persistence .FieldResult ;
16
16
import jakarta .persistence .Id ;
17
+ import jakarta .persistence .LockModeType ;
17
18
import jakarta .persistence .SqlResultSetMapping ;
18
19
19
20
/**
57
58
entityClass = SimpleEntityWithNamedMappings .class
58
59
)
59
60
)
61
+ @ SqlResultSetMapping (
62
+ name = "entity-lockmode" ,
63
+ entities = @ EntityResult (
64
+ entityClass = SimpleEntityWithNamedMappings .class ,
65
+ lockMode = LockModeType .PESSIMISTIC_WRITE
66
+ )
67
+ )
60
68
@ SqlResultSetMapping (
61
69
name = "entity-id-notes" ,
62
70
entities = @ EntityResult (
You can’t perform that action at this time.
0 commit comments