Patrick Lübbecke (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=61a7428...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZGIyNGRkN2Yx...
) / Improvement (
https://hibernate.atlassian.net/browse/HHH-15599?atlOrigin=eyJpIjoiZGIyNG...
) HHH-15599 (
https://hibernate.atlassian.net/browse/HHH-15599?atlOrigin=eyJpIjoiZGIyNG...
) Support conditional order-by clauses in QueryBuilder (
https://hibernate.atlassian.net/browse/HHH-15599?atlOrigin=eyJpIjoiZGIyNG...
)
Issue Type: Improvement Affects Versions: 5.6.12 Assignee: Unassigned Created: 12/Oct/2022
03:53 AM Priority: Minor Reporter: Patrick Lübbecke (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=61a7428...
)
I would like to add conditional order by operators to CriteriaBuilder like that:
order by rmgtnav_path, rmgtnav_collection_type<>'PROFILE',
rmgtnav_denotation asc
Or as Order objects:
List<Order> orderStatements = new ArrayList();
orderStatements.add(cb.asc(root.get("rmgtnav_path")));
orderStatements.add(cb.asc(cb.notEqual(root.get("rmgtnav_collection_type"),
"PROFILE")));
orderStatements.add(cb.asc(root.get("rmgtnav_denotation")));
criteriQuery.orderBy(orderStatements);
Query query = session.createQuery(cq);
What the rmgtnav_collection_type<> 'Profile' part does is to resolve the
statement as a boolean which is true (1) or false (0) and start sorting with
collection_type = Profile on top in my case. Unfortunately, I get an error when calling
session.createQuery(cq) method:
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node: <> near
line 1, column 596 [select generatedAlias0 from
com.myapp.core.rmgt.rate.business.object.RmgtBVOImpl as generatedAlias0 where (
generatedAlias0.collectionType<>:param0 ) and ( (
generatedAlias0.collectionSubType<>:param1 ) or ( generatedAlias0.collectionSubType
is null ) ) and ( ( lower(generatedAlias0.profileStatus) like :param2 ) and ( (
generatedAlias0.type=:param3 ) or ( generatedAlias0.type=:param4 ) ) ) and (
generatedAlias0.enabled=:param5 ) and ( ( generatedAlias0.owner=:param6 ) or (
generatedAlias0.owner=:param7 ) ) order by generatedAlias0.path asc,
generatedAlias0.collectionType<>:param8 asc, generatedAlias0.denotation asc]
I think it would be beneficial, If criteriaBuilder would also allow to add these kind of
statements.
(
https://hibernate.atlassian.net/browse/HHH-15599#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-15599#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#100208- sha1:399748d )