Skip to content

Commit 83c52f9

Browse files
committed
HHH-18069 - Add test
Signed-off-by: Jan Schatteman <[email protected]>
1 parent 0cc02b7 commit 83c52f9

File tree

2 files changed

+149
-50
lines changed

2 files changed

+149
-50
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/DomainModelTestCase.java

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
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.query;
8+
9+
import java.time.LocalDate;
10+
11+
import org.hibernate.query.Query;
12+
13+
import org.hibernate.testing.orm.junit.DomainModel;
14+
import org.hibernate.testing.orm.junit.FailureExpected;
15+
import org.hibernate.testing.orm.junit.SessionFactory;
16+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
17+
import org.junit.jupiter.api.Test;
18+
19+
import jakarta.persistence.Entity;
20+
import jakarta.persistence.GeneratedValue;
21+
import jakarta.persistence.GenerationType;
22+
import jakarta.persistence.Id;
23+
import jakarta.persistence.ManyToOne;
24+
25+
/**
26+
* @author Jan Schatteman
27+
*/
28+
@DomainModel (
29+
annotatedClasses = { UnionPartionTest.Apple.class, UnionPartionTest.Pie.class }
30+
)
31+
@SessionFactory
32+
public class UnionPartionTest {
33+
34+
@Test
35+
@FailureExpected
36+
public void testUnionPartitionResults(SessionFactoryScope scope) {
37+
scope.inTransaction(
38+
session -> {
39+
String q = "SELECT new CurrentApple(id, bakedPie.id, dir)\n" +
40+
"FROM (\n" +
41+
"(\n" +
42+
" SELECT\n" +
43+
" id id, bakedPie bakedPie, bakedOn bakedOn,\n" +
44+
" MAX(bakedOn) OVER (PARTITION BY bakedPie.id) mbo,\n" +
45+
" -1 dir\n" +
46+
" FROM Apple c\n" +
47+
" WHERE\n" +
48+
" bakedPie.id IN (1,2,3,4)\n" +
49+
" AND bakedOn <= :now\n" +
50+
"\n" +
51+
") UNION ALL (\n" +
52+
"\n" +
53+
" SELECT\n" +
54+
" id id, bakedPie bakedPie, bakedOn bakedOn,\n" +
55+
" MIN(bakedOn) OVER (PARTITION BY bakedPie.id) mbo,\n" +
56+
" 1 dir\n" +
57+
" FROM Apple c\n" +
58+
" WHERE\n" +
59+
" bakedPie.id IN (1,2,3,4)\n" +
60+
" AND bakedOn > :now\n" +
61+
")\n" +
62+
")\n" +
63+
"WHERE bakedOn = mbo\n" +
64+
"ORDER BY dir";
65+
Query<CurrentApple> query = session.createQuery( q, CurrentApple.class );
66+
query.setParameter( "now", LocalDate.now());
67+
68+
query.getSingleResult();
69+
}
70+
);
71+
}
72+
73+
public static class CurrentApple {
74+
private final int id;
75+
private final int pieId;
76+
private final int dir;
77+
78+
public CurrentApple(int id, int pieId, int dir) {
79+
this.id = id;
80+
this.pieId = pieId;
81+
this.dir = dir;
82+
}
83+
public int getDir() {
84+
return dir;
85+
}
86+
public int getId() {
87+
return id;
88+
}
89+
public int getPieId() {
90+
return pieId;
91+
}
92+
}
93+
94+
@Entity(name = "Apple")
95+
public static class Apple {
96+
@Id
97+
@GeneratedValue(strategy = GenerationType.IDENTITY)
98+
private Integer id;
99+
private LocalDate bakedOn;
100+
@ManyToOne
101+
private Pie bakedPie;
102+
103+
public Integer getId() {
104+
return id;
105+
}
106+
public Apple setId(Integer id) {
107+
this.id = id;
108+
return this;
109+
}
110+
public LocalDate getBakedOn() {
111+
return bakedOn;
112+
}
113+
public Apple setBakedOn(LocalDate bakedOn) {
114+
this.bakedOn = bakedOn;
115+
return this;
116+
}
117+
public Pie getBakedPie() {
118+
return bakedPie;
119+
}
120+
public Apple setBakedPie(Pie bakedPie) {
121+
this.bakedPie = bakedPie;
122+
return this;
123+
}
124+
}
125+
126+
@Entity(name = "Pie")
127+
public static class Pie {
128+
@Id
129+
@GeneratedValue(strategy = GenerationType.IDENTITY)
130+
private Integer id;
131+
private String taste;
132+
133+
public Integer getId() {
134+
return id;
135+
}
136+
public Pie setId(Integer id) {
137+
this.id = id;
138+
return this;
139+
}
140+
public String getTaste() {
141+
return taste;
142+
}
143+
public Pie setTaste(String taste) {
144+
this.taste = taste;
145+
return this;
146+
}
147+
}
148+
149+
}

0 commit comments

Comments
 (0)