30
30
import org .junit .jupiter .api .BeforeEach ;
31
31
import org .junit .jupiter .api .Test ;
32
32
33
+ import jakarta .persistence .Entity ;
34
+ import jakarta .persistence .Id ;
35
+ import jakarta .persistence .ManyToOne ;
36
+ import jakarta .persistence .MappedSuperclass ;
33
37
import jakarta .persistence .Tuple ;
34
38
35
39
import static org .junit .jupiter .api .Assertions .assertEquals ;
41
45
standardModels = StandardDomainModel .CONTACTS ,
42
46
annotatedClasses = {
43
47
CountQueryTests .SimpleDto .class ,
48
+ CountQueryTests .BaseAttribs .class ,
49
+ CountQueryTests .IdBased .class ,
50
+ CountQueryTests .ParentEntity .class ,
51
+ CountQueryTests .ChildEntity .class ,
44
52
}
45
53
)
46
54
@ SessionFactory
@@ -200,6 +208,22 @@ public void testUnionQuery(SessionFactoryScope scope) {
200
208
} );
201
209
}
202
210
211
+ @ Test
212
+ @ Jira ( "https://hibernate.atlassian.net/browse/HHH-18357" )
213
+ public void testJoinedEntityPath (SessionFactoryScope scope ) {
214
+ scope .inTransaction ( session -> {
215
+ final HibernateCriteriaBuilder cb = session .getCriteriaBuilder ();
216
+ verifyCount ( session , cb .createQuery (
217
+ "select c.id, c.parent from ChildEntity c" ,
218
+ Tuple .class
219
+ ) );
220
+ verifyCount ( session , cb .createQuery (
221
+ "select distinct c.id, c.parent from ChildEntity c" ,
222
+ Tuple .class
223
+ ) );
224
+ } );
225
+ }
226
+
203
227
@ BeforeEach
204
228
public void prepareTestData (SessionFactoryScope scope ) {
205
229
scope .inTransaction ( (session ) -> {
@@ -273,6 +297,15 @@ public void prepareTestData(SessionFactoryScope scope) {
273
297
session .persist ( c4 );
274
298
session .persist ( c8 );
275
299
session .persist ( c7 );
300
+
301
+ final ParentEntity p1 = new ParentEntity ( "parent_1" , 1L );
302
+ final ParentEntity p2 = new ParentEntity ( "parent_2" , 2L );
303
+ final ChildEntity c1 = new ChildEntity ( "child_1" , 1L , p1 );
304
+ final ChildEntity c2 = new ChildEntity ( "child_2" , 2L , p2 );
305
+ session .persist ( p1 );
306
+ session .persist ( p2 );
307
+ session .persist ( c1 );
308
+ session .persist ( c2 );
276
309
} );
277
310
}
278
311
@@ -287,6 +320,8 @@ public void dropTestData(SessionFactoryScope scope) {
287
320
scope .inTransaction ( (session ) -> {
288
321
session .createMutationQuery ( "update Contact set alternativeContact = null" ).executeUpdate ();
289
322
session .createMutationQuery ( "delete Contact" ).executeUpdate ();
323
+ session .createMutationQuery ( "delete ChildEntity" ).executeUpdate ();
324
+ session .createMutationQuery ( "delete ParentEntity" ).executeUpdate ();
290
325
} );
291
326
}
292
327
@@ -298,4 +333,54 @@ public SimpleDto(String name) {
298
333
this .name = name ;
299
334
}
300
335
}
336
+
337
+ @ MappedSuperclass
338
+ static class BaseAttribs {
339
+ private String description ;
340
+
341
+ public BaseAttribs () {
342
+ }
343
+
344
+ public BaseAttribs (String description ) {
345
+ this .description = description ;
346
+ }
347
+ }
348
+
349
+ @ MappedSuperclass
350
+ static class IdBased extends BaseAttribs {
351
+ @ Id
352
+ private Long id ;
353
+
354
+ public IdBased () {
355
+ }
356
+
357
+ public IdBased (String description , Long id ) {
358
+ super ( description );
359
+ this .id = id ;
360
+ }
361
+ }
362
+
363
+ @ Entity ( name = "ParentEntity" )
364
+ static class ParentEntity extends IdBased {
365
+ public ParentEntity () {
366
+ }
367
+
368
+ public ParentEntity (String description , Long id ) {
369
+ super ( description , id );
370
+ }
371
+ }
372
+
373
+ @ Entity ( name = "ChildEntity" )
374
+ static class ChildEntity extends IdBased {
375
+ @ ManyToOne
376
+ private ParentEntity parent ;
377
+
378
+ public ChildEntity () {
379
+ }
380
+
381
+ public ChildEntity (String description , Long id , ParentEntity parent ) {
382
+ super ( description , id );
383
+ this .parent = parent ;
384
+ }
385
+ }
301
386
}
0 commit comments