Case statement with nested select in HQL

I have a problem creating an HQL statement for this SQL (Oracle).

SELECT CASE WHEN Column1 = 'VALUE1' THEN ( SELECT COL2 FROM Table1 ) ELSE Column3 END FROM TABLE2 WHERE Columnx = 'something that is unique' 

HQL is more like the same. The problem is that the nested choice is in the case.

Error:

 java.lang.NullPointerException at org.hibernate.hql.ast.tree.CaseNode.getDataType(CaseNode.java:40) at org.hibernate.hql.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:165) at org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:831) at org.hibernate.hql.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:619) at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:672) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:288) at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:231) at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80) at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94) at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156) at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135) at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1651) 

For 99%, mappings of Table1 and Table2 are in context.

Any advice would be appreciated.

+4
source share
1 answer

Is there only one entry in table 1? if not, then choosing from it inside the case will not work, try joining table1 and table2, for example:

  SELECT CASE WHEN Column1 = 'VALUE1' THEN ( COL2 ) ELSE Column3 END AS CASE1 FROM TABLE2 , Table1 WHERE Columnx = 'something that is unique' 

if table2, tabl3 needs to be combined, then do not forget to do this if the Cartesian connection does not occur.

0
source

All Articles