Skip to content

Commit 4d2b659

Browse files
committed
[#2154] Test Composite Id with generated values
1 parent f7a251f commit 4d2b659

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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.junit.jupiter.api.Test;
9+
10+
import io.vertx.junit5.Timeout;
11+
import io.vertx.junit5.VertxTestContext;
12+
import jakarta.persistence.Entity;
13+
import jakarta.persistence.GeneratedValue;
14+
import jakarta.persistence.Id;
15+
import jakarta.persistence.IdClass;
16+
import jakarta.persistence.SequenceGenerator;
17+
import java.util.Collection;
18+
import java.util.List;
19+
20+
import static java.util.concurrent.TimeUnit.MINUTES;
21+
22+
@Timeout(value = 10, timeUnit = MINUTES)
23+
24+
public class CompositeIdWithGeneratedValuesTest extends BaseReactiveTest{
25+
26+
@Override
27+
protected Collection<Class<?>> annotatedEntities() {
28+
return List.of( Product.class);
29+
}
30+
31+
@Test
32+
public void testCompositeIdWithGeneratedValues(VertxTestContext context) {
33+
Product product = new Product("name", 1L);
34+
test( context, openSession()
35+
.thenCompose( session -> session
36+
.persist( product )
37+
.thenCompose( v -> session.flush() ))
38+
);
39+
}
40+
41+
@Entity
42+
@IdClass(ProductId.class)
43+
public static class Product {
44+
@Id
45+
private Long version;
46+
47+
@Id
48+
@GeneratedValue
49+
@SequenceGenerator(name = "product_seq", sequenceName = "product_seq")
50+
private Long id;
51+
52+
private String name;
53+
54+
public Product() {
55+
}
56+
57+
public Product(String name, Long version) {
58+
this.name = name;
59+
this.version = version;
60+
}
61+
62+
public Long getVersion() {
63+
return version;
64+
}
65+
66+
public void setVersion(Long version) {
67+
this.version = version;
68+
}
69+
70+
public Long getId() {
71+
return id;
72+
}
73+
74+
public String getName() {
75+
return name;
76+
}
77+
78+
}
79+
80+
public static class ProductId {
81+
private Long version;
82+
private Long id;
83+
84+
private ProductId() {
85+
}
86+
87+
public ProductId(Long version, Long id) {
88+
this.version = version;
89+
this.id = id;
90+
}
91+
}
92+
}

0 commit comments

Comments
 (0)