HQL-EntityManager.createQuery在CaseInsensitiveComparator.comp



我正试图用多个SELECT语句中的列创建一个SELECT查询,但由于NPE而失败。下面是查询,然后是堆栈跟踪。谢谢你的帮助!

Query query = em.createQuery("SELECT DISTINCT " +
"(SELECT count(*) AS totalPlayers FROM TeamEntity t, AssignmentsEntity a, JerseyEntity p " +
"WHERE t.id = a.teamid AND p.jerseyId = a.jerseyid and t.id = :teamId), " +
"(SELECT count(*) AS activePlayers FROM TeamEntity t2, AssignmentsEntity a2, JerseyEntity " +
"WHERE t2.id = a2.teamid AND JerseyEntity.jerseyid = a2.jerseyid AND t2.id = :teamId " +
"AND starttime > 0) " +
"FROM TeamEntity");
query.setParameter("teamId", teamId);
java.lang.NullPointerException
at java.lang.String$CaseInsensitiveComparator.compare(String.java:1192)
at java.lang.String$CaseInsensitiveComparator.compare(String.java:1186)
at java.util.TreeMap.getEntryUsingComparator(TreeMap.java:376)
at java.util.TreeMap.getEntry(TreeMap.java:345)
at java.util.TreeMap.get(TreeMap.java:278)
at org.hibernate.dialect.function.SQLFunctionRegistry.findSQLFunction(SQLFunctionRegistry.java:45)
at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.findSQLFunction(SessionFactoryHelper.java:385)
at org.hibernate.hql.internal.ast.tree.IdentNode.getDataType(IdentNode.java:374)
at org.hibernate.hql.internal.ast.HqlSqlWalker.lookupProperty(HqlSqlWalker.java:659)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.addrExpr(HqlSqlBaseWalker.java:5002)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1286)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4706)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:4174)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2138)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2066)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2063)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2063)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:815)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:609)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:2466)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:2232)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1503)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:585)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:313)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:261)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:271)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:191)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:143)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:119)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:153)
at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:597)
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:706)
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:731)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:23)

不是我想要的确切解决方案,但我只是使用了em.createNativeQuery((,这对我来说很有用。希望它不会给我带来任何麻烦。

你试过这个吗?

Query query = em.createQuery("SELECT DISTINCT " +
"(SELECT count(*) AS totalPlayers FROM TeamEntity t, AssignmentsEntity a, JerseyEntity p " +
"WHERE t.id = a.teamid AND p.jerseyId = a.jerseyid and t.id = :teamId), " +
"(SELECT count(*) AS activePlayers FROM TeamEntity t2, AssignmentsEntity a2, JerseyEntity p " +
"WHERE t2.id = a2.teamid AND p.jerseyid = a2.jerseyid AND t2.id = :teamId " +
"AND starttime > 0) " +
"FROM TeamEntity");

最新更新