Bartlomiej Niemiec (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5cdd0b2...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNTM3N2YyMzE4...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16409?atlOrigin=eyJpIjoiNTM3N2...
) HHH-16409 (
https://hibernate.atlassian.net/browse/HHH-16409?atlOrigin=eyJpIjoiNTM3N2...
) SQLGrammarException when selecting property of grouped join association (
https://hibernate.atlassian.net/browse/HHH-16409?atlOrigin=eyJpIjoiNTM3N2...
)
Issue Type: Bug Affects Versions: 6.2.0 Assignee: Unassigned Attachments: testcase.zip
Components: hibernate-core Created: 31/Mar/2023 01:54 AM Environment: JDK 17, Postgres,
HSQLDB Priority: Major Reporter: Bartlomiej Niemiec (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5cdd0b2...
)
Having entities like:
@Entity
@Table(schema = "test" , name = "t_primary" )
public class Primary implements Serializable {
@Id
private int id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "t_secondary_id" )
private Secondary secondary;
private BigDecimal value;
//getters & setters
@Entity
@Table(schema = "test" , name = "t_secondary" )
public class Secondary implements Serializable {
@Id
private int id;
private String name;
//getters & setters
and executing following query:
CriteriaBuilder cb = em.getCriteriaBuilder();
var query = cb.createTupleQuery();
Root<Primary> root = query.from(Primary.class);
var secondaryJoin = root.join(Primary_.secondary);
//when
query.multiselect(
secondaryJoin.get(Secondary_.name).alias( "secondary" ),
cb.sum(root.get(Primary_.value)).alias( "sum" )
).groupBy(
secondaryJoin
).orderBy(
cb.desc(secondaryJoin.get(Secondary_.name))
);
var list = em.createQuery(query).getResultList();
will cause exception:
java. sql.SQLSyntaxErrorException: expression not in aggregate or GROUP BY columns : S1_0.
NAME in statement [ select s1_0. name , sum (p1_0. value ) from test.t_primary p1_0 join
test.t_secondary s1_0 on s1_0.id=p1_0.t_secondary_id group by p1_0.t_secondary_id order by
1 desc ]
This example works fine in 5.6.x and 6.1.0
(
https://hibernate.atlassian.net/browse/HHH-16409#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16409#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100221- sha1:57c27f3 )