Nguyễn Tuấn
Nguyễn Tuấn

Reputation: 37

Get unexpected token when execute Hibernate Query

I am trying to execute this query:

String hql = "select e.donvi from " + BIDVTygia.class.getName() + 
    " e where e.dateUpdate = (select * from (select v.dateUpdate from " + 
    BIDVTygia.class.getName() + " v order by v.dateUpdate desc  ) where ROWNUM = 1)";

I get an error:

unexpected token: (

or

unexpected token: *

or

unexpected token: where

What I'm doing wrong? Thanks in advance.

Upvotes: 0

Views: 502

Answers (1)

Youcef LAIDANI
Youcef LAIDANI

Reputation: 59950

Try to use an alias in the second select, then use it to get only the returned value :

select
   e.donvi 
from
   BIDVTygia.class.getName() e 
where
   e.dateUpdate = 
   (
      select
         ALIAS_NAME.dateUpdate -- <---------Use the alias to get the value (don't return *)
      from 
         (
            select
               v.dateUpdate 
            from
               BIDVTygia.class.getName() v 
            order by
               v.dateUpdate desc
         )
         ALIAS_NAME -- <--------------------Use an alias
      where
         ROWNUM = 1
   )

Upvotes: 1

Related Questions