Skip to content

Commit 692304d

Browse files
DavideDdreab8
authored andcommitted
[#1867] Test case
1 parent b1d93d8 commit 692304d

File tree

3 files changed

+641
-67
lines changed

3 files changed

+641
-67
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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+
9+
import org.junit.jupiter.api.Test;
10+
11+
import io.vertx.junit5.Timeout;
12+
import io.vertx.junit5.VertxTestContext;
13+
import jakarta.persistence.Entity;
14+
import jakarta.persistence.GeneratedValue;
15+
import jakarta.persistence.GenerationType;
16+
import jakarta.persistence.Id;
17+
import jakarta.persistence.Inheritance;
18+
import jakarta.persistence.InheritanceType;
19+
import jakarta.persistence.SequenceGenerator;
20+
import jakarta.persistence.Table;
21+
import java.util.Collection;
22+
import java.util.List;
23+
import java.util.concurrent.CompletionStage;
24+
25+
import static java.util.concurrent.TimeUnit.MINUTES;
26+
import static org.assertj.core.api.Assertions.assertThat;
27+
import static org.hibernate.reactive.util.impl.CompletionStages.voidFuture;
28+
29+
@Timeout(value = 10, timeUnit = MINUTES)
30+
public class JoinedInheritanceBatchTest extends BaseReactiveTest {
31+
32+
@Override
33+
protected Collection<Class<?>> annotatedEntities() {
34+
return List.of( ClientA.class, Client.class );
35+
}
36+
37+
@Override
38+
protected CompletionStage<Void> cleanDb() {
39+
return voidFuture();
40+
}
41+
42+
@Test
43+
public void test(VertxTestContext context) {
44+
final ClientA client1 = new ClientA("Client 1", "email@c1", "123456");
45+
46+
test( context, getMutinySessionFactory().withTransaction( session -> {
47+
session.setBatchSize( 5 );
48+
return session
49+
.persist( client1 )
50+
.chain( session::flush )
51+
.chain( () -> session.createQuery( "select c from Client c" )
52+
.getResultList()
53+
.invoke( persistedClients -> assertThat( persistedClients )
54+
.as( "Clients has not bee persisted" )
55+
.isNotEmpty() ) );
56+
} )
57+
);
58+
}
59+
60+
@Entity(name = "Client")
61+
@Table(name = "`Client`")
62+
@Inheritance(strategy = InheritanceType.JOINED)
63+
public static class Client {
64+
65+
@Id
66+
@SequenceGenerator(name = "seq", sequenceName = "id_seq", allocationSize = 1)
67+
@GeneratedValue(generator = "seq", strategy = GenerationType.SEQUENCE)
68+
private Long id;
69+
70+
private String name;
71+
72+
private String email;
73+
74+
private String phone;
75+
76+
public Client() {
77+
}
78+
79+
public Client(String name, String email, String phone) {
80+
this.name = name;
81+
this.email = email;
82+
this.phone = phone;
83+
}
84+
85+
public Long getId() {
86+
return id;
87+
}
88+
89+
public void setId(Long id) {
90+
this.id = id;
91+
}
92+
93+
public String getName() {
94+
return name;
95+
}
96+
97+
public void setName(String name) {
98+
this.name = name;
99+
}
100+
101+
public String getEmail() {
102+
return email;
103+
}
104+
105+
public void setEmail(String email) {
106+
this.email = email;
107+
}
108+
109+
public String getPhone() {
110+
return phone;
111+
}
112+
113+
public void setPhone(String phone) {
114+
this.phone = phone;
115+
}
116+
117+
}
118+
119+
@Entity
120+
@Table(name = "`ClientA`")
121+
public static class ClientA extends Client {
122+
123+
public ClientA() {
124+
}
125+
126+
public ClientA(String name, String email, String phone) {
127+
super( name, email, phone );
128+
}
129+
}
130+
131+
}

0 commit comments

Comments
 (0)