HHH-16672 test case

This commit is contained in:
Daniel Mensinger 2023-12-01 14:17:29 +01:00 committed by Andrea Boriero
parent 7407b02813
commit c41d85887a
1 changed files with 39 additions and 0 deletions

View File

@ -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 {