Skip to content

Commit fa3b256

Browse files
dreab8DavideD
authored andcommitted
[#2332] Add test for SqlException, Reactive doesn't use JDBC when locking previously loaded entity
1 parent 660daeb commit fa3b256

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/* Hibernate, Relational Persistence for Idiomatic Java
2+
*
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Copyright: Red Hat Inc. and Hibernate Authors
5+
*/
6+
package org.hibernate.reactive;
7+
8+
import org.hibernate.LockMode;
9+
10+
import org.junit.jupiter.api.Test;
11+
12+
import io.vertx.junit5.Timeout;
13+
import io.vertx.junit5.VertxTestContext;
14+
import jakarta.persistence.Entity;
15+
import jakarta.persistence.Id;
16+
import jakarta.persistence.Table;
17+
18+
import java.util.Collection;
19+
import java.util.List;
20+
21+
import static java.util.concurrent.TimeUnit.MINUTES;
22+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
23+
24+
@Timeout(value = 10, timeUnit = MINUTES)
25+
public class LockOnLoadTest extends BaseReactiveTest{
26+
@Override
27+
protected Collection<Class<?>> annotatedEntities() {
28+
return List.of( Person.class );
29+
}
30+
31+
@Test
32+
public void testLockOnLoad(VertxTestContext context) {
33+
Person person = new Person( 1L, "Davide" );
34+
35+
test( context, getMutinySessionFactory()
36+
.withTransaction( session -> session.persist( person ) )
37+
.call( () -> getMutinySessionFactory().withSession( session -> session
38+
.find( Person.class, person.getId() )
39+
// the issue occurred when trying to find the same entity but upgrading the lock mode
40+
.chain( p -> session.find( Person.class, person.getId(), LockMode.PESSIMISTIC_WRITE ) )
41+
.invoke( p -> assertThat( p ).isNotNull() )
42+
) )
43+
);
44+
}
45+
46+
@Entity(name = "Person")
47+
@Table(name = "LockOnLoadTest.Person")
48+
public static class Person {
49+
@Id
50+
private Long id;
51+
52+
private String name;
53+
54+
public Person() {
55+
}
56+
57+
public Person(Long id, String name) {
58+
this.id = id;
59+
this.name = name;
60+
}
61+
62+
public Long getId() {
63+
return id;
64+
}
65+
66+
public String getName() {
67+
return name;
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)