mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-08 20:24:46 +00:00
HHH-16672 test case
This commit is contained in:
parent
7407b02813
commit
c41d85887a
@ -27,6 +27,7 @@
|
|||||||
import org.hibernate.query.Query;
|
import org.hibernate.query.Query;
|
||||||
|
|
||||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
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.Jpa;
|
||||||
import org.hibernate.testing.orm.junit.RequiresDialect;
|
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
@ -35,6 +36,7 @@
|
|||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -189,6 +191,43 @@ public void testFollowOnLocking(EntityManagerFactoryScope scope) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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[]
|
//tag::locking-jpa-query-hints-scope-entity-example[]
|
||||||
@Entity(name = "Person")
|
@Entity(name = "Person")
|
||||||
public static class Person {
|
public static class Person {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user