0

I have a sql query which says

select case when col='city' then (select name from Table) end AliasName 
    from SomeOtherTable

I am unable to use subqueries in hql case-when-then expression. Is there any other method I can accomplish the same

mostafa.S
  • 1,452
  • 4
  • 16
  • 27
  • Try without `=` (see https://forum.hibernate.org/viewtopic.php?t=942197) –  Dec 09 '12 at 07:50
  • 1
    please share your real query, do Table and SomeOtherTable have a relation? – mostafa.S Dec 09 '12 at 11:28
  • The SQL will not work anyway, unless `Table` has only 1 row. – ypercubeᵀᴹ Dec 09 '12 at 11:33
  • @RC: problem is with the subquery part, the rest query is working. But, as soon as I add subquery part, it raises the exception. – user1345619 Dec 09 '12 at 15:17
  • 1
    @Mostafa: I have SomeOtherTable which has a column varchar COL which has value either 'city' or 'region'. I have to display the name of city if the COL has 'city' from table TABLE (i havent shown the rest part, the ID need to be matched from SOMEOTHERTABLE and TABLE). If the COL value says 'region', I have to display the name of region rom TABLE2. There is no relation as of now (I could not define the mapping of SomeOtherTable since TABLE and TABLE2 are associated with the same column) – user1345619 Dec 09 '12 at 15:21
  • your table information belongs in your question. Please edit your question to add the needed information. – carbontax Dec 10 '12 at 14:55

1 Answers1

0

This is a workaround rather a direct answer; create a view in database and a new class in your application. now you are free of your hql totally.

of course this link is about another question but somehow relates to yours and talks about features that are not supported in HQL or are hard to implement: Hibernate Union alternatives

Community
  • 1
  • 1
mostafa.S
  • 1,452
  • 4
  • 16
  • 27