HHH-16672 test case
This commit is contained in:
parent
dc71c17503
commit
aba5ac47a0
|
@ -27,6 +27,7 @@ import org.hibernate.dialect.OracleDialect;
|
|||
import org.hibernate.query.Query;
|
||||
|
||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.JiraKey;
|
||||
import org.hibernate.testing.orm.junit.Jpa;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
|
@ -35,6 +36,7 @@ import org.junit.jupiter.api.Test;
|
|||
import org.jboss.logging.Logger;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -189,6 +191,43 @@ public class ExplicitLockingTest {
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@JiraKey("HHH-16672")
|
||||
public void persistAndLock(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(entityManager -> {
|
||||
Person person = new Person("John Doe");
|
||||
entityManager.persist(person);
|
||||
entityManager.lock(person, LockModeType.PESSIMISTIC_WRITE);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@JiraKey("HHH-16672")
|
||||
public void persistFindAndLock(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(entityManager -> {
|
||||
Person person = new Person("John Doe");
|
||||
entityManager.persist(person);
|
||||
assertNotNull(person.id);
|
||||
|
||||
Person foundPerson = entityManager.find(Person.class, person.id);
|
||||
entityManager.lock(foundPerson, LockModeType.PESSIMISTIC_WRITE);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@JiraKey("HHH-16672")
|
||||
public void persistFindWithLock(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(entityManager -> {
|
||||
Person person = new Person("John Doe");
|
||||
entityManager.persist(person);
|
||||
assertNotNull(person.id);
|
||||
|
||||
Person foundPerson = entityManager.find(Person.class, person.id, LockModeType.PESSIMISTIC_WRITE);
|
||||
assertNotNull(foundPerson);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//tag::locking-jpa-query-hints-scope-entity-example[]
|
||||
@Entity(name = "Person")
|
||||
public static class Person {
|
||||
|
|
Loading…
Reference in New Issue