Hibernate CASE WHEN expression not using arithmetic operation


#1

org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: * near line 1, column 46 [select case when p.name like ‘person%’ then 2*p.id else p.id end from com.ipinyou.mip.mdb.model.Person p]


#2

hibernate orm 5.3.7

select 
    case when p.name like ‘person%’ 
    then 2*p.id 
    else p.id end 
from com.ipinyou.mip.mdb.model.Person p

#3

I created HHH-13095 for it and submitted a PR for updating the docs.

You need to use parenthesis to wrap the arithmetic expression:

select 
    case when p.name like ‘person%’ 
    then (2*p.id) 
    else p.id end 
from com.ipinyou.mip.mdb.model.Person p