Skip to content

Commit 8f3cc24

Browse files
dreab8beikov
authored andcommitted
HHH-17632 Add test for issue
1 parent b8d9552 commit 8f3cc24

File tree

1 file changed

+184
-0
lines changed

1 file changed

+184
-0
lines changed
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
package org.hibernate.orm.test.bytecode.enhancement.update;
2+
3+
import java.util.List;
4+
5+
import org.hibernate.annotations.Formula;
6+
7+
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
8+
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
9+
import org.hibernate.testing.orm.junit.JiraKey;
10+
import org.junit.After;
11+
import org.junit.Before;
12+
import org.junit.Test;
13+
import org.junit.runner.RunWith;
14+
15+
import jakarta.persistence.Basic;
16+
import jakarta.persistence.Column;
17+
import jakarta.persistence.DiscriminatorColumn;
18+
import jakarta.persistence.Entity;
19+
import jakarta.persistence.Id;
20+
import jakarta.persistence.Inheritance;
21+
import jakarta.persistence.InheritanceType;
22+
import jakarta.persistence.Table;
23+
24+
import static jakarta.persistence.FetchType.LAZY;
25+
import static org.junit.jupiter.api.Assertions.assertEquals;
26+
import static org.junit.jupiter.api.Assertions.assertFalse;
27+
import static org.junit.jupiter.api.Assertions.assertTrue;
28+
29+
30+
@RunWith(BytecodeEnhancerRunner.class)
31+
@JiraKey("HHH-17632")
32+
public class JoinedInheritanceTest extends BaseNonConfigCoreFunctionalTestCase {
33+
34+
@Override
35+
protected Class[] getAnnotatedClasses() {
36+
return new Class[] {
37+
Plane.class, A320.class
38+
};
39+
}
40+
41+
@Before
42+
public void setUp() {
43+
inTransaction(
44+
session -> {
45+
A320 a320 = new A320( 1l, "Airbus A320", 101, true, "1.0" );
46+
session.persist( a320 );
47+
}
48+
);
49+
}
50+
51+
@After
52+
public void tearDown() {
53+
inTransaction(
54+
session -> {
55+
session.createMutationQuery( "delete from A320" ).executeUpdate();
56+
}
57+
);
58+
}
59+
60+
@Test
61+
public void testUpdateField() {
62+
inTransaction(
63+
session -> {
64+
A320 referenceById = session.getReference( A320.class, 1L );
65+
66+
referenceById.setSoftwareVersion( "2.0" );
67+
68+
session.flush();
69+
session.clear();
70+
71+
List<A320> airbusA320 = session.createQuery(
72+
"select a from A320 a where a.description = 'Airbus A320'" ).getResultList();
73+
assertFalse( airbusA320.isEmpty() );
74+
assertEquals( 1, airbusA320.size() );
75+
A320 a320 = airbusA320.get( 0 );
76+
assertEquals( "2.0", a320.getSoftwareVersion() );
77+
assertTrue( a320.getLarge() );
78+
}
79+
);
80+
}
81+
82+
@Test
83+
public void testUpdateTwoFields() {
84+
inTransaction(
85+
session -> {
86+
A320 referenceById = session.getReference( A320.class, 1L );
87+
88+
referenceById.setSoftwareVersion( "2.0" );
89+
referenceById.setNbrOfSeats( 103 );
90+
91+
session.flush();
92+
session.clear();
93+
94+
List<A320> airbusA320 = session.createQuery(
95+
"select a from A320 a where a.description like 'Airbus A320'" ).getResultList();
96+
assertFalse( airbusA320.isEmpty() );
97+
assertEquals( 1, airbusA320.size() );
98+
A320 a320 = airbusA320.get( 0 );
99+
assertEquals( "2.0", a320.getSoftwareVersion() );
100+
assertEquals( 103, a320.getNbrOfSeats() );
101+
assertTrue( a320.getLarge() );
102+
}
103+
);
104+
}
105+
106+
107+
@Entity(name = "A320")
108+
@Table(name = "a320")
109+
public static class A320 extends Plane {
110+
111+
@Column(name = "software_version")
112+
private String softwareVersion;
113+
114+
public A320() {
115+
super();
116+
}
117+
118+
public A320(Long id, String description, int nbrOfSeats, Boolean large, String softwareVersion) {
119+
super( id, description, nbrOfSeats, large );
120+
this.softwareVersion = softwareVersion;
121+
}
122+
123+
public String getSoftwareVersion() {
124+
return softwareVersion;
125+
}
126+
127+
public void setSoftwareVersion(String softwareVersion) {
128+
this.softwareVersion = softwareVersion;
129+
}
130+
}
131+
132+
@Table(name = "plane_table")
133+
@Inheritance(strategy = InheritanceType.JOINED)
134+
@DiscriminatorColumn
135+
@Entity(name = "Plane")
136+
public static class Plane {
137+
138+
@Id
139+
private Long id;
140+
141+
@Column
142+
private String description;
143+
144+
@Column(name = "nbr_of_seats")
145+
private int nbrOfSeats;
146+
147+
@Basic(fetch = LAZY)
148+
private Boolean large = false;
149+
150+
public Plane() {
151+
}
152+
153+
public Plane(Long id, String description, int nbrOfSeats, Boolean large) {
154+
this.id = id;
155+
this.description = description;
156+
this.nbrOfSeats = nbrOfSeats;
157+
this.large = large;
158+
}
159+
160+
public String getDescription() {
161+
return description;
162+
}
163+
164+
public void setDescription(String description) {
165+
this.description = description;
166+
}
167+
168+
public int getNbrOfSeats() {
169+
return nbrOfSeats;
170+
}
171+
172+
public void setNbrOfSeats(int nbrOfSeats) {
173+
this.nbrOfSeats = nbrOfSeats;
174+
}
175+
176+
public Boolean getLarge() {
177+
return large;
178+
}
179+
180+
public void setLarge(Boolean large) {
181+
this.large = large;
182+
}
183+
}
184+
}

0 commit comments

Comments
 (0)