Skip to content

Commit d64b956

Browse files
jrenaatbeikov
authored andcommitted
HHH-17943 - Add test for issue
Signed-off-by: Jan Schatteman <[email protected]>
1 parent 3570d9b commit d64b956

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
5+
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
6+
*/
7+
package org.hibernate.orm.test.dialect.unit;
8+
9+
import org.hibernate.dialect.H2Dialect;
10+
11+
import org.hibernate.testing.orm.junit.DomainModel;
12+
import org.hibernate.testing.orm.junit.JiraKey;
13+
import org.hibernate.testing.orm.junit.RequiresDialect;
14+
import org.hibernate.testing.orm.junit.SessionFactory;
15+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
16+
import org.junit.jupiter.api.Test;
17+
18+
import jakarta.persistence.Entity;
19+
import jakarta.persistence.Id;
20+
import jakarta.persistence.Inheritance;
21+
import jakarta.persistence.InheritanceType;
22+
23+
import static org.junit.jupiter.api.Assertions.assertNull;
24+
25+
/**
26+
* @author Jan Schatteman
27+
*/
28+
@DomainModel(
29+
annotatedClasses = {
30+
H2DialectTempTableNoCommitTest.Person.class,
31+
H2DialectTempTableNoCommitTest.Engineer.class,
32+
H2DialectTempTableNoCommitTest.Doctor.class
33+
}
34+
)
35+
@SessionFactory
36+
@RequiresDialect( H2Dialect.class )
37+
@JiraKey( "HHH-17943" )
38+
public class H2DialectTempTableNoCommitTest {
39+
40+
@Test
41+
public void noCommitAfterTempTableCreationTest(SessionFactoryScope scope) {
42+
scope.inTransaction(
43+
session -> {
44+
// the following shouldn't commit anything to the DB
45+
Doctor d = new Doctor();
46+
d.setId( 2L );
47+
session.persist( d );
48+
session.flush();
49+
session.createMutationQuery( "update Engineer set fellow = false where fellow = true" ).executeUpdate();
50+
session.getTransaction().markRollbackOnly();
51+
}
52+
);
53+
scope.inTransaction(
54+
session -> {
55+
assertNull(session.find( Doctor.class, 2L ));
56+
}
57+
);
58+
}
59+
60+
@Entity(name = "Person")
61+
@Inheritance(strategy = InheritanceType.JOINED)
62+
public static class Person {
63+
64+
@Id
65+
private Long id;
66+
67+
public Long getId() {
68+
return id;
69+
}
70+
71+
public void setId(Long id) {
72+
this.id = id;
73+
}
74+
}
75+
76+
@Entity(name = "Engineer")
77+
public static class Engineer extends Person {
78+
79+
private boolean fellow;
80+
81+
public boolean isFellow() {
82+
return fellow;
83+
}
84+
85+
public void setFellow(boolean fellow) {
86+
this.fellow = fellow;
87+
}
88+
}
89+
90+
@Entity(name = "Doctor")
91+
public static class Doctor {
92+
@Id
93+
private Long id;
94+
private String name;
95+
96+
public Long getId() {
97+
return id;
98+
}
99+
100+
public void setId(Long id) {
101+
this.id = id;
102+
}
103+
104+
public String getName() {
105+
return name;
106+
}
107+
108+
public void setName(String name) {
109+
this.name = name;
110+
}
111+
}
112+
113+
}

0 commit comments

Comments
 (0)