h2数据库to_char别名抛出空指针
Posted
技术标签:
【中文标题】h2数据库to_char别名抛出空指针【英文标题】:h2 database to_char alias throwing null pointer 【发布时间】:2014-03-20 20:56:50 【问题描述】:HQL 在 oracle 数据库中运行良好,但在使用 h2 数据库 1.3 时抛出空指针。 175
Query q = session.createQuery(
"select new TESTPOJO(c.name, c.phoneNumber, " +
"to_char(c.dateofBirth, 'YY') from STUDENT c " +
"where c.gender= :gender " +
"group by to_char(c.dateofBirth, 'YY') );
q.setString("gender", "Male");
result = q.list();
下面是日志...如何在H2中使用to_char()
别名
java.lang.NullPointerException
at org.hibernate.internal.util.ReflectHelper.getConstructor(ReflectHelper.java:355)
at org.hibernate.hql.internal.ast.tree.ConstructorNode.resolveConstructor(ConstructorNode.java:179)
at org.hibernate.hql.internal.ast.tree.ConstructorNode.prepare(ConstructorNode.java:152)
at org.hibernate.hql.internal.ast.HqlSqlWalker.processConstructor(HqlSqlWalker.java:1019)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:2150)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:2016)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1451)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:571)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:105)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:219)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:197)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1736)
at com.ens.stomp.schema.ect4.dao.ClaimsReportingDAO.getFrontEndRejections(ClaimsReportingDAO.java:180)
at com.ens.stomp.persistence.claim.professional.v5010.h2.ect4.ECT4ReportingDAOTest.testGetFrontEndRejections(ECT4ReportingDAOTest.java:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.lang.reflect.Method.invoke(Method.java:606)
at util.h2.SessionFactoryRule$1.evaluate(SessionFactoryRule.java:54)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
【问题讨论】:
请尝试使用代码格式化工具使您的帖子更具可读性 【参考方案1】:使用较新的 H2 db 版本 1.3.175。自 2014-01-18 起可使用 TO_CHAR 函数。
【讨论】:
以上是关于h2数据库to_char别名抛出空指针的主要内容,如果未能解决你的问题,请参考以下文章