10
10
11
11
import org .hibernate .testing .orm .junit .DialectFeatureChecks ;
12
12
import org .hibernate .testing .orm .junit .DomainModel ;
13
- import org .hibernate .testing .orm .junit .FailureExpected ;
13
+ import org .hibernate .testing .orm .junit .JiraKey ;
14
14
import org .hibernate .testing .orm .junit .RequiresDialectFeature ;
15
15
import org .hibernate .testing .orm .junit .SessionFactory ;
16
16
import org .hibernate .testing .orm .junit .SessionFactoryScope ;
25
25
/**
26
26
* @author Jan Schatteman
27
27
*/
28
- @ DomainModel (
29
- annotatedClasses = { UnionOfPartitionResultsTest .Apple .class , UnionOfPartitionResultsTest .Pie .class }
28
+ @ DomainModel (
29
+ annotatedClasses = {UnionOfPartitionResultsTest .Apple .class , UnionOfPartitionResultsTest .Pie .class }
30
30
)
31
31
@ SessionFactory
32
+ @ JiraKey ( "HHH-18069" )
32
33
public class UnionOfPartitionResultsTest {
33
34
34
35
@ Test
35
- @ FailureExpected
36
36
@ RequiresDialectFeature (feature = DialectFeatureChecks .SupportsUnion .class )
37
+ public void testSubqueryWithUnion (SessionFactoryScope scope ) {
38
+ scope .inTransaction (
39
+ session -> {
40
+ String q = "SELECT id " +
41
+ "FROM " +
42
+ "( " +
43
+ "( SELECT id id, bakedPie bakedPie " +
44
+ "\t FROM Apple c " +
45
+ ") " +
46
+ "\t UNION ALL " +
47
+ "( SELECT id id, bakedPie bakedPie " +
48
+ "\t FROM Apple a " +
49
+ ") " +
50
+ ")" ;
51
+
52
+ Query query = session .createQuery ( q );
53
+
54
+ query .list ();
55
+ }
56
+ );
57
+ }
58
+
59
+ @ Test
60
+ public void testSubquery (SessionFactoryScope scope ) {
61
+ scope .inTransaction (
62
+ session -> {
63
+ String q = "SELECT id " +
64
+ "FROM " +
65
+ "( " +
66
+ "\t SELECT id id, bakedPie bakedPie " +
67
+ "\t FROM Apple c " +
68
+ ")" ;
69
+
70
+ Query query = session .createQuery ( q );
71
+
72
+ query .list ();
73
+ }
74
+ );
75
+ }
76
+
77
+ @ Test
78
+ @ RequiresDialectFeature (feature = DialectFeatureChecks .SupportsUnion .class )
79
+ public void testUnionQuery (SessionFactoryScope scope ) {
80
+ scope .inTransaction (
81
+ session -> {
82
+ String q = "( SELECT id id, bakedPie bakedPie " +
83
+ "\t FROM Apple c " +
84
+ ") " +
85
+ "\t UNION ALL " +
86
+ "( SELECT id id, bakedPie bakedPie " +
87
+ "\t FROM Apple c " +
88
+ ") " ;
89
+
90
+ Query query = session .createQuery ( q );
91
+
92
+ query .list ();
93
+ }
94
+ );
95
+ }
96
+
97
+
98
+ @ Test
99
+ @ RequiresDialectFeature (feature = DialectFeatureChecks .SupportsUnion .class )
100
+ @ RequiresDialectFeature (feature = DialectFeatureChecks .SupportPartitionBy .class )
37
101
public void testUnionOfPartitionResults (SessionFactoryScope scope ) {
38
102
scope .inTransaction (
39
103
session -> {
40
104
String q =
41
105
"SELECT new CurrentApple(id, bakedPie.id, dir) " +
42
106
"FROM (" +
43
- "(" +
44
- "SELECT id id, bakedPie bakedPie, bakedOn bakedOn, MAX(bakedOn) OVER (PARTITION BY bakedPie.id) mbo, -1 dir " +
45
- "FROM Apple c " +
46
- "WHERE bakedPie.id IN (1,2,3,4) AND bakedOn <= :now" +
47
- ") UNION ALL (" +
48
- "SELECT id id, bakedPie bakedPie, bakedOn bakedOn, MIN(bakedOn) OVER (PARTITION BY bakedPie.id) mbo, 1 dir " +
49
- "FROM Apple c " +
50
- "WHERE bakedPie.id IN (1,2,3,4) AND bakedOn > :now" +
51
- ")" +
107
+ "(" +
108
+ "SELECT id id, bakedPie bakedPie, bakedOn bakedOn, MAX(bakedOn) OVER (PARTITION BY bakedPie.id) mbo, -1 dir " +
109
+ "FROM Apple c " +
110
+ "WHERE bakedPie.id IN (1,2,3,4) AND bakedOn <= :now" +
111
+ ") UNION ALL (" +
112
+ "SELECT id id, bakedPie bakedPie, bakedOn bakedOn, MIN(bakedOn) OVER (PARTITION BY bakedPie.id) mbo, 1 dir " +
113
+ "FROM Apple c " +
114
+ "WHERE bakedPie.id IN (1,2,3,4) AND bakedOn > :now" +
115
+ ")" +
52
116
") " +
53
117
"WHERE bakedOn = mbo ORDER BY dir" ;
54
118
55
119
Query <CurrentApple > query = session .createQuery ( q , CurrentApple .class );
56
120
query .setParameter ( "now" , LocalDate .now ());
57
121
58
- query .getSingleResult ();
122
+ query .list ();
59
123
}
60
124
);
61
125
}
62
126
127
+
63
128
public static class CurrentApple {
64
129
private final int id ;
65
130
private final int pieId ;
@@ -70,12 +135,15 @@ public CurrentApple(int id, int pieId, int dir) {
70
135
this .pieId = pieId ;
71
136
this .dir = dir ;
72
137
}
138
+
73
139
public int getDir () {
74
140
return dir ;
75
141
}
142
+
76
143
public int getId () {
77
144
return id ;
78
145
}
146
+
79
147
public int getPieId () {
80
148
return pieId ;
81
149
}
@@ -93,20 +161,25 @@ public static class Apple {
93
161
public Integer getId () {
94
162
return id ;
95
163
}
164
+
96
165
public Apple setId (Integer id ) {
97
166
this .id = id ;
98
167
return this ;
99
168
}
169
+
100
170
public LocalDate getBakedOn () {
101
171
return bakedOn ;
102
172
}
173
+
103
174
public Apple setBakedOn (LocalDate bakedOn ) {
104
175
this .bakedOn = bakedOn ;
105
176
return this ;
106
177
}
178
+
107
179
public Pie getBakedPie () {
108
180
return bakedPie ;
109
181
}
182
+
110
183
public Apple setBakedPie (Pie bakedPie ) {
111
184
this .bakedPie = bakedPie ;
112
185
return this ;
@@ -123,13 +196,16 @@ public static class Pie {
123
196
public Integer getId () {
124
197
return id ;
125
198
}
199
+
126
200
public Pie setId (Integer id ) {
127
201
this .id = id ;
128
202
return this ;
129
203
}
204
+
130
205
public String getTaste () {
131
206
return taste ;
132
207
}
208
+
133
209
public Pie setTaste (String taste ) {
134
210
this .taste = taste ;
135
211
return this ;
0 commit comments