|
| 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.persist( client1 ); |
| 49 | + } ) |
| 50 | + .chain( () -> getMutinySessionFactory().withTransaction( session -> session |
| 51 | + .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 | + @Entity(name = "Client") |
| 60 | + @Table(name = "`Client`") |
| 61 | + @Inheritance(strategy = InheritanceType.JOINED) |
| 62 | + public static class Client { |
| 63 | + |
| 64 | + @Id |
| 65 | + @SequenceGenerator(name = "seq", sequenceName = "id_seq", allocationSize = 1) |
| 66 | + @GeneratedValue(generator = "seq", strategy = GenerationType.SEQUENCE) |
| 67 | + private Long id; |
| 68 | + |
| 69 | + private String name; |
| 70 | + |
| 71 | + private String email; |
| 72 | + |
| 73 | + private String phone; |
| 74 | + |
| 75 | + public Client() { |
| 76 | + } |
| 77 | + |
| 78 | + public Client(String name, String email, String phone) { |
| 79 | + this.name = name; |
| 80 | + this.email = email; |
| 81 | + this.phone = phone; |
| 82 | + } |
| 83 | + |
| 84 | + public Long getId() { |
| 85 | + return id; |
| 86 | + } |
| 87 | + |
| 88 | + public void setId(Long id) { |
| 89 | + this.id = id; |
| 90 | + } |
| 91 | + |
| 92 | + public String getName() { |
| 93 | + return name; |
| 94 | + } |
| 95 | + |
| 96 | + public void setName(String name) { |
| 97 | + this.name = name; |
| 98 | + } |
| 99 | + |
| 100 | + public String getEmail() { |
| 101 | + return email; |
| 102 | + } |
| 103 | + |
| 104 | + public void setEmail(String email) { |
| 105 | + this.email = email; |
| 106 | + } |
| 107 | + |
| 108 | + public String getPhone() { |
| 109 | + return phone; |
| 110 | + } |
| 111 | + |
| 112 | + public void setPhone(String phone) { |
| 113 | + this.phone = phone; |
| 114 | + } |
| 115 | + |
| 116 | + } |
| 117 | + |
| 118 | + @Entity |
| 119 | + @Table(name = "`ClientA`") |
| 120 | + public static class ClientA extends Client { |
| 121 | + |
| 122 | + public ClientA() { |
| 123 | + } |
| 124 | + |
| 125 | + public ClientA(String name, String email, String phone) { |
| 126 | + super( name, email, phone ); |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | +} |
0 commit comments