• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPQL: Multiple parameters for SELECT

 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


In the above sample, there are multiple parameters for the SELECT clause as c.user and c.categoryId

In this case, I couldn't understand that what will be returned as the result of this code.

Please help.
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this a valid query at all? There is a grouping function (COUNT) and an entity in the select, but there is not group by clause. Does it not give some king of query exception?
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops! I've missed it

This is the exact code:



I couldn't understand that what will be returned as the result of this code. Because there are two parameters in the SELECT clause. Then how the result will be produced?
 
Ralph Jaus
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assume table Category looks like

Then your query - in a first step - "groups by" the users. This looks internally like

In a second step the categoryId's are counted per user:
And that's just what the query returns.
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Query returns a table?
Thank you Ralph.
 
Ralph Jaus
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, if you run the query as query.getResultList() it returns a list of object arrays with array length 2: The first index of the array represents c.user and the second count(c.categoryId). If you represent this list graphically it looks like the indicated table.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic