I have written several HQL queries for my application, such as this one: <query name="States.PrimaryKey">from States where Name = ?</query> to retrieve Primary Keys from tables so that I can store them in a table that is loaded with Foreign Keys. However, the following query: <query name="ActionType.PrimaryKey">from ActionType where ActionType = ?</query> generates the following exception:
Exception in thread "main" java.lang.ExceptionInInitializerError at gov.nrc.wbl.reader.DataReader.main(DataReader.java:78) Caused by: java.lang.NullPointerException at org.hibernate.hql.ast.util.SessionFactoryHelper.findSQLFunction(SessionFactoryHelper.java:364) at org.hibernate.hql.ast.tree.IdentNode.getDataType(IdentNode.java:293) at org.hibernate.hql.ast.tree.BinaryLogicOperatorNode.extractDataType(BinaryLogicOperatorNode.java:232) at org.hibernate.hql.ast.tree.BinaryLogicOperatorNode.initialize(BinaryLogicOperatorNode.java:58) at org.hibernate.hql.ast.HqlSqlWalker.prepareLogicOperator(HqlSqlWalker.java:1199) at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:4414) at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2047) at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:831) at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:617) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:301) at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:244) 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:124) at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:549) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:413) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872) at gov.nrc.wbl.persistence.DataPersister.<clinit>(DataPersister.java:28) ... 1 more
If I change the query to read like this:
<query name="ActionType.PrimaryKey">from ActionType where actionType = ?</query>
it works fine. I ran the following SQL against my database and, as expected, both queries returned the same data:
select * from Radmat.dbo.ActionType where ActionType = 'Renewal'; select * from Radmat.dbo.ActionType where actionType = 'Renewal';
What's confusing to me is this: the first query references TableName/ColumnName but the second query references Object/Field. I thought Hibernate abstracted away that difference when using HQL. What am I not understanding, or is this a bug?
|