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

JPQL

 
Deepika Joshi
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Select o
2. From Order o
3. Where o.qty>50
4. ORDER BY o.item

I thought removing removing line 4. would make it valid query, my logic is o.item is not part of select statement (first line).

Is it correct?


Thanks.
 
Ralph Jaus
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the query expression is valid as it is ('select o' contains each state field and single value assocation field since it is resolved by the persistence provider like 'select o.name, o.item, o.price, ... from order o ...').
 
Deepika Joshi
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To use GROUP BY we need to mention field name in Select clause,
don't we need to follow same rule for ORDER BY.

Am I correct?

Thanks.
 
Ralph Jaus
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From JPA spec 4.9 (order by):
When the ORDER BY clause is used in a query, each element of the SELECT clause of the query must be one of the following:
1. an identification variable x
2. a single_valued_path_expression
3. a state_field_path_expression

So you can use identifaction variables without causing problems (see also the ORDER BY examples in the quoted JPA reference).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic