@Test
public void failingTest() throws Exception {
// BaseCoreFunctionalTestCase automatically creates the SessionFactory and
// provides the Session.
try (Session s = openSession()) {
Transaction tx = s.beginTransaction();
String hql = "select new org.hibernate.bugs.MyPojo (sum(e.amount), re ) from org.hibernate.bugs.MyEntity e join e.relatedEntity re where 1=1 group by re";
Query<MyPojo> query = s.createQuery(hql, MyPojo.class);
List<MyPojo> actual = query.list();
assertThat(actual).isEmpty();
// Verify the generated SQL
// In oracle we get ORA-00979 not a group by expression
tx.commit();
}
}
Hibernate:
select
sum(m1_0.amount),
r1_0.ID,
r1_0.DISC_COL,
r1_0.RELATED_VALUE,
r1_0.ONLY_CHILD_ONE,
r1_0.ONLY_CHILD_TWO
from
MY_TABLE m1_0
join
MY_TABLE r1_0
on r1_0.ID=m1_0.REL_ENTITY
where
1=1
group by
r1_0.ID,
r1_0.DISC_COL,
r1_0.RELATED_VALUE
The generated group by does not include the r1_0.ONLY_CHILD_ONE and r1_0.ONLY_CHILD_TWO