Skip to content

Commit ba07dca

Browse files
committed
HHH-13612 Add test for issue
1 parent 5b3770e commit ba07dca

File tree

1 file changed

+135
-0
lines changed

1 file changed

+135
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
* SPDX-License-Identifier: LGPL-2.1-or-later
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.annotations.formula;
6+
7+
import jakarta.persistence.Column;
8+
import jakarta.persistence.Entity;
9+
import jakarta.persistence.GeneratedValue;
10+
import jakarta.persistence.Id;
11+
import jakarta.persistence.Table;
12+
import org.hibernate.annotations.Formula;
13+
import org.hibernate.testing.orm.junit.DomainModel;
14+
import org.hibernate.testing.orm.junit.JiraKey;
15+
import org.hibernate.testing.orm.junit.SessionFactory;
16+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
17+
import org.junit.jupiter.api.BeforeAll;
18+
import org.junit.jupiter.api.Test;
19+
20+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
21+
22+
@JiraKey("HHH-13612")
23+
@DomainModel(
24+
annotatedClasses = {
25+
FormulaWithQuotedTableNamesAndQuotedColumnNamesTest.TestEntity.class,
26+
FormulaWithQuotedTableNamesAndQuotedColumnNamesTest.TestEntity2.class
27+
}
28+
)
29+
@SessionFactory
30+
public class FormulaWithQuotedTableNamesAndQuotedColumnNamesTest {
31+
32+
private final static Long TEST_ENTITY_ID = 1L;
33+
34+
@BeforeAll
35+
public void setUp(SessionFactoryScope scope) {
36+
scope.inTransaction( session -> {
37+
TestEntity testEntity = new TestEntity();
38+
testEntity.setId( TEST_ENTITY_ID );
39+
testEntity.setIntegerValue( 2 );
40+
session.persist( testEntity );
41+
42+
TestEntity2 testEntity2 = new TestEntity2();
43+
testEntity2.setAnotherIntegerValue( 1 );
44+
testEntity2.setSelect( 3 );
45+
session.persist( testEntity2 );
46+
} );
47+
}
48+
49+
@Test
50+
public void testThatTheTableNamesAreNotQualifiedWithGeneratedAliases(SessionFactoryScope scope) {
51+
scope.inTransaction( session -> {
52+
TestEntity testEntity = session.get( TestEntity.class, TEST_ENTITY_ID );
53+
assertThat( testEntity ).isNotNull();
54+
} );
55+
}
56+
57+
58+
@Entity(name = "TestEntity")
59+
@Table(name = "TEST_ENTITY")
60+
public static class TestEntity {
61+
@Id
62+
@Column(name = "ID")
63+
private Long id;
64+
65+
@Column(name = "INTEGER_VALUE")
66+
private Integer integerValue;
67+
68+
@Formula(
69+
"( select te.`INTEGER_VALUE` + te2.`select` + te2.`ANOTHER_STRING_VALUE` from `TEST_ENTITY` te, `TEST_ENTITY_2` te2 where te.`ID` = 1)"
70+
)
71+
private Integer computedIntegerValue;
72+
73+
public Long getId() {
74+
return id;
75+
}
76+
77+
public void setId(Long id) {
78+
this.id = id;
79+
}
80+
81+
public Integer getComputedIntegerValue() {
82+
return computedIntegerValue;
83+
}
84+
85+
public void setComputedIntegerValue(Integer computedIntegerValue) {
86+
this.computedIntegerValue = computedIntegerValue;
87+
}
88+
89+
public Integer getIntegerValue() {
90+
return integerValue;
91+
}
92+
93+
public void setIntegerValue(Integer integerValue) {
94+
this.integerValue = integerValue;
95+
}
96+
}
97+
98+
@Entity(name = "TestEntity2")
99+
@Table(name = "TEST_ENTITY_2")
100+
public static class TestEntity2 {
101+
@Id
102+
@GeneratedValue
103+
private Long id;
104+
105+
@Column(name = "ANOTHER_STRING_VALUE")
106+
private Integer anotherIntegerValue;
107+
108+
@Column(name = "`select`")
109+
private Integer select;
110+
111+
public Long getId() {
112+
return id;
113+
}
114+
115+
public void setId(Long id) {
116+
this.id = id;
117+
}
118+
119+
public Integer getAnotherIntegerValue() {
120+
return anotherIntegerValue;
121+
}
122+
123+
public void setAnotherIntegerValue(Integer anotherIntegerValue) {
124+
this.anotherIntegerValue = anotherIntegerValue;
125+
}
126+
127+
public Integer getSelect() {
128+
return select;
129+
}
130+
131+
public void setSelect(Integer select) {
132+
this.select = select;
133+
}
134+
}
135+
}

0 commit comments

Comments
 (0)