Skip to content

Commit a476288

Browse files
dreab8beikov
authored andcommitted
HHH-17380 Add test for issue
1 parent 3413b47 commit a476288

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package org.hibernate.orm.test.version;
2+
3+
import org.hibernate.testing.orm.junit.DomainModel;
4+
import org.hibernate.testing.orm.junit.JiraKey;
5+
import org.hibernate.testing.orm.junit.SessionFactory;
6+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
7+
import org.junit.jupiter.api.AfterEach;
8+
import org.junit.jupiter.api.Test;
9+
10+
import jakarta.persistence.Entity;
11+
import jakarta.persistence.Id;
12+
import jakarta.persistence.JoinColumn;
13+
import jakarta.persistence.MapsId;
14+
import jakarta.persistence.OneToOne;
15+
import jakarta.persistence.Version;
16+
17+
@DomainModel(
18+
annotatedClasses = {
19+
EntityWithNullVersionAndMapsIdTest.Person.class,
20+
EntityWithNullVersionAndMapsIdTest.Address.class,
21+
}
22+
)
23+
@SessionFactory
24+
@JiraKey("HHH-17380")
25+
public class EntityWithNullVersionAndMapsIdTest {
26+
27+
@AfterEach
28+
public void tearDown(SessionFactoryScope scope) {
29+
scope.inTransaction(
30+
session -> {
31+
session.createMutationQuery( "delete from Person" );
32+
session.createMutationQuery( "delete from Address" );
33+
34+
}
35+
);
36+
}
37+
38+
@Test
39+
public void testPersistEntityWithMapsId(SessionFactoryScope scope) {
40+
Address address = new Address( "Alex" );
41+
scope.inTransaction(
42+
session -> {
43+
session.persist( address );
44+
Person person = new Person( address );
45+
session.persist( person );
46+
}
47+
);
48+
}
49+
50+
@Entity(name = "Person")
51+
public static class Person {
52+
53+
@Id
54+
private String name;
55+
56+
@Version
57+
private Long version;
58+
59+
private String description;
60+
61+
@MapsId
62+
@OneToOne
63+
@JoinColumn(name = "name")
64+
private Address address;
65+
66+
public Person() {
67+
}
68+
69+
public Person(Address address) {
70+
this.name = address.getName();
71+
this.address = address;
72+
}
73+
74+
public String getName() {
75+
return name;
76+
}
77+
78+
public Address getAddress() {
79+
return address;
80+
}
81+
}
82+
83+
@Entity(name = "Address")
84+
public static class Address {
85+
@Id
86+
private String name;
87+
88+
@Version
89+
private Long version;
90+
91+
private String description;
92+
93+
public Address() {
94+
}
95+
96+
public Address(String name) {
97+
this.name = name;
98+
}
99+
100+
public String getName() {
101+
return name;
102+
}
103+
}
104+
}

0 commit comments

Comments
 (0)