Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Unexpected AST node: query
PostPosted: Tue Jun 27, 2017 3:46 am 
Beginner
Beginner

Joined: Sat Jun 24, 2006 7:05 am
Posts: 20
My query is:

Code:
select utenteTmpl
from axioma.web.template.model.domain.UtenteTmpl utenteTmpl
order by (select parent.descrizione
from axioma.web.template.model.domain.LingueTmpl parent
where entity.lingua = parent.pk.codice) asc


I get an error "unexpected AST node: query".

Is not supported to use a subquery as sort?

Oracle DB and SAP Hana support such syntax (I'm working on Oracle).


Top
 Profile  
 
 Post subject: Re: unexpected AST node: query
PostPosted: Tue Jun 27, 2017 4:22 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1229
Code:
Is not supported use a subquery as sort ?


According to Hibernate User Guide, which you should read it, this is what's supported in the HQL ORDER BY clause:

Quote:
The types of expressions considered valid as part of the ORDER BY clause include:

- state fields

- component/embeddable attributes

- scalar expressions such as arithmetic operations, functions, etc.

- identification variable declared in the select clause for any of the previous expression types


So, it does not support nested selects.

Quote:
Oracle DB and SAP Hana support such syntax (I'm working on Oracle).


Just because Hibernate offers HQL, it does not mean you have to use it for everything. Otherwise, why do you think Hibernate and JPA allow you to run Native SQL queries?

HQL is suitable to fetch entities that you plan on modifying. Otherwise, just use DTO projections. You can use the ResultTransformer to build any type of DTO projection you like (e.g. trees, graphs, etc)

So, just write the query in SQL.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.