如何解决疯狂的 JPA 需求?
Posted
技术标签:
【中文标题】如何解决疯狂的 JPA 需求?【英文标题】:How to solve Crazy JPA Requirements? 【发布时间】:2016-04-27 08:25:22 【问题描述】:在我的项目中,我使用 JPA 1.0 和 Hibernate 3.2.x 和 Tomcat 进行部署。
在我的项目中,我使用以下查询作为命名查询执行,
SELECT smSSTJob.smJob.jobId, smSSTJob.smJob.jobTypeId, smSSTJob.omObject.objectId,
smSSTJob.omObject.objectName FROM SMSSTJob smSSTJob
WHERE smSSTJob.smJob.jobTypeId IN (:jobTypeIdList)
AND smSSTJob.jobStatusId IN (:jobStatusList)
AND smSSTJob.omObject.objectId NOT IN (SELECT sm.omObject.objectId FROM SMSSTJob sm
WHERE sm.jobStatusId IN (:unProcessedJobStatusList)
AND sm.responseReceivedDate > :responseReceivedDate)
AND smSSTJob.priority = :priority
AND smSSTJob.jobRetries < :maximumJobRetries ORDER BY smSSTJob.smJob.jobId
当我部署我的项目时,上述查询休眠引发了以下异常,
Caused by: java.lang.NullPointerException
at org.hibernate.hql.ast.tree.FromClause.findIntendedAliasedFromElementBasedOnCrazyJPARequirements(FromClause.java:120)
at org.hibernate.hql.ast.tree.FromClause.getFromElement(FromClause.java:107)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:81)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:255)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.collectionFunctionOrSubselect(HqlSqlBaseWalker.java:4253)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.inRhs(HqlSqlBaseWalker.java:4161)
如何解决此异常?任何人都请在这种情况下帮助我。 提前致谢。
【问题讨论】:
您是否检查了smSSTJob.smJob.jobTypeId
中的smJob
和smSSTJob.omObject.objectId
中的omObject
不是null
?
smSSTJob
中的 smJob
和 omObject
都是 foreign key and not null 列。
Hibernate 3.2.6 或更低版本?
休眠版本是3.2.5ga
"Its still broken in the latest 3.2.5 GA download."
见here
【参考方案1】:
Hibernate中有一个bug,3.2.6及以后解决,尝试更新Hibernate版本
【讨论】:
【参考方案2】:可能是缺少一个“)”吗?关闭您的子查询。
不在(从 SMSSTJob sm 中选择 sm.omObject.objectId WHERE sm.jobStatusId IN (:unProcessedJobStatusList)
【讨论】:
没有错……不在(从 SMSSTJob sm WHERE sm.jobStatusId IN (:unProcessedJobStatusList) AND sm.responseReceivedDate > :responseReceivedDate) 中选择 sm.omObject.objectId)以上是关于如何解决疯狂的 JPA 需求?的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 graphql-jpa java 解决 graphql n+1 问题?
spring jpa使用@service注解时失效该如何解决?
如何解决无法添加或更新子行:Spring JPA 中的外键约束失败错误?
mysql+springboot+jpa查询几十万条数据很慢 如何解决?