Skip to content

Commit 28c108c

Browse files
committed
HHH-18357 Add test for issue
1 parent 6086684 commit 28c108c

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/query/criteria/CountQueryTests.java

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
import org.junit.jupiter.api.BeforeEach;
3131
import org.junit.jupiter.api.Test;
3232

33+
import jakarta.persistence.Entity;
34+
import jakarta.persistence.Id;
35+
import jakarta.persistence.ManyToOne;
36+
import jakarta.persistence.MappedSuperclass;
3337
import jakarta.persistence.Tuple;
3438

3539
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -41,6 +45,10 @@
4145
standardModels = StandardDomainModel.CONTACTS,
4246
annotatedClasses = {
4347
CountQueryTests.SimpleDto.class,
48+
CountQueryTests.BaseAttribs.class,
49+
CountQueryTests.IdBased.class,
50+
CountQueryTests.ParentEntity.class,
51+
CountQueryTests.ChildEntity.class,
4452
}
4553
)
4654
@SessionFactory
@@ -200,6 +208,22 @@ public void testUnionQuery(SessionFactoryScope scope) {
200208
} );
201209
}
202210

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+
203227
@BeforeEach
204228
public void prepareTestData(SessionFactoryScope scope) {
205229
scope.inTransaction( (session) -> {
@@ -273,6 +297,15 @@ public void prepareTestData(SessionFactoryScope scope) {
273297
session.persist( c4 );
274298
session.persist( c8 );
275299
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 );
276309
} );
277310
}
278311

@@ -287,6 +320,8 @@ public void dropTestData(SessionFactoryScope scope) {
287320
scope.inTransaction( (session) -> {
288321
session.createMutationQuery( "update Contact set alternativeContact = null" ).executeUpdate();
289322
session.createMutationQuery( "delete Contact" ).executeUpdate();
323+
session.createMutationQuery( "delete ChildEntity" ).executeUpdate();
324+
session.createMutationQuery( "delete ParentEntity" ).executeUpdate();
290325
} );
291326
}
292327

@@ -298,4 +333,54 @@ public SimpleDto(String name) {
298333
this.name = name;
299334
}
300335
}
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+
}
301386
}

0 commit comments

Comments
 (0)