test for @EntityResult(lockMode)
Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
parent
27042f562f
commit
e11ac26cd2
|
@ -17,6 +17,7 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import jakarta.persistence.LockModeType;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.query.named.NamedResultSetMappingMemento;
|
import org.hibernate.query.named.NamedResultSetMappingMemento;
|
||||||
|
|
||||||
|
@ -119,6 +120,29 @@ public class EntityResultTests extends AbstractUsageTest {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testImplicitAttributeMappingWithLockMode(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
session -> {
|
||||||
|
// make sure it is in the repository
|
||||||
|
final NamedResultSetMappingMemento mappingMemento = session.getSessionFactory()
|
||||||
|
.getQueryEngine()
|
||||||
|
.getNamedObjectRepository()
|
||||||
|
.getResultSetMappingMemento(
|
||||||
|
"entity-lockmode" );
|
||||||
|
assertThat( mappingMemento, notNullValue() );
|
||||||
|
|
||||||
|
// apply it to a native-query
|
||||||
|
final String qryString = "select id, name, notes from SimpleEntityWithNamedMappings for update";
|
||||||
|
final List<SimpleEntityWithNamedMappings> results = session
|
||||||
|
.createNativeQuery( qryString, "entity-lockmode" )
|
||||||
|
.list();
|
||||||
|
assertThat( results.size(), is( 1 ) );
|
||||||
|
assertThat( session.getLockMode(results.get(0)), is(LockModeType.PESSIMISTIC_WRITE));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMixedAttributeMapping(SessionFactoryScope scope) {
|
public void testMixedAttributeMapping(SessionFactoryScope scope) {
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
|
|
|
@ -14,6 +14,7 @@ import jakarta.persistence.EntityResult;
|
||||||
import jakarta.persistence.FetchType;
|
import jakarta.persistence.FetchType;
|
||||||
import jakarta.persistence.FieldResult;
|
import jakarta.persistence.FieldResult;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.LockModeType;
|
||||||
import jakarta.persistence.SqlResultSetMapping;
|
import jakarta.persistence.SqlResultSetMapping;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,6 +58,13 @@ import jakarta.persistence.SqlResultSetMapping;
|
||||||
entityClass = SimpleEntityWithNamedMappings.class
|
entityClass = SimpleEntityWithNamedMappings.class
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@SqlResultSetMapping(
|
||||||
|
name = "entity-lockmode",
|
||||||
|
entities = @EntityResult(
|
||||||
|
entityClass = SimpleEntityWithNamedMappings.class,
|
||||||
|
lockMode = LockModeType.PESSIMISTIC_WRITE
|
||||||
|
)
|
||||||
|
)
|
||||||
@SqlResultSetMapping(
|
@SqlResultSetMapping(
|
||||||
name = "entity-id-notes",
|
name = "entity-id-notes",
|
||||||
entities = @EntityResult(
|
entities = @EntityResult(
|
||||||
|
|
Loading…
Reference in New Issue