This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Order BY clause in JPQL

 
Sivapradeep Reddy Duggireddy
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a SQL query that works fine in MySQL.

SELECT e.email FROM Educator e ORDER BY (e.spocInvig + e.educInvig);

its fetching rows based on the spocinvig and educinvig sum in ascending order.

but in JPQL i'm getting exception like this.
Exception Description: Syntax error parsing the query [SELECT e.email FROM Educator e ORDER BY (e.spocInvig + e.educInvig)], line 1, column 41: syntax error at [(].
Internal Exception: line 1:41: expecting IDENT, found '('

Can anyone suggest me proper JPQL for the given SQL ?
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What JPA provider and version are you using?

Did you try just removing the brackets?

SELECT e.email FROM Educator e ORDER BY e.spocInvig + e.educInvig

 
Rajit vreddi
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you use jpql then use custom result class to resolve the issue.create a class called ABC and create method getSum(a,b) which returns the sum of two values .
the query looks like

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic