Skip to content

Commit e0818b2

Browse files
committed
[#2332] Add test for SqlException, Reactive doesn't use JDBC when locking previously loaded entity
1 parent bd300dc commit e0818b2

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 java.util.Collection;
17+
import java.util.List;
18+
19+
import static java.util.concurrent.TimeUnit.MINUTES;
20+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
21+
22+
@Timeout(value = 10, timeUnit = MINUTES)
23+
public class LockOnLoadTest extends BaseReactiveTest{
24+
@Override
25+
protected Collection<Class<?>> annotatedEntities() {
26+
return List.of( Person.class );
27+
}
28+
29+
@Test
30+
public void testLockOnLoad(VertxTestContext context) {
31+
Person person = new Person( 1L, "Davide" );
32+
33+
test( context, getMutinySessionFactory()
34+
.withTransaction( session -> session.persist( person ) )
35+
.call( () -> getMutinySessionFactory().withSession( session -> session
36+
.find( Person.class, person.getId() )
37+
// the issue occurred when trying to find the same entity but upgrading the lock mode
38+
.chain( p -> session.find( Person.class, person.getId(), LockMode.PESSIMISTIC_WRITE ) )
39+
.invoke( p -> assertThat( p ).isNotNull() )
40+
) )
41+
);
42+
}
43+
44+
@Entity(name = "Person")
45+
public static class Person {
46+
@Id
47+
private Long id;
48+
49+
private String name;
50+
51+
public Person() {
52+
}
53+
54+
public Person(Long id, String name) {
55+
this.id = id;
56+
this.name = name;
57+
}
58+
59+
public Long getId() {
60+
return id;
61+
}
62+
63+
public String getName() {
64+
return name;
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)