gpt4 book ai didi

java - 这个 HQL 查询有什么问题?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:19:31 24 4
gpt4 key购买 nike

我是遇到了 hibernate 错误还是遇到了我没有看到的错误:

select enty.number from EntityAliasName enty
where enty.myId in
(
select cons.myId from Consens cons where cons.number in
(
select ord.number from Orders ord where ord.customer = :customer
and ord.creationDate <
(
select max(ord.creationDate) from Orders ord where ord.customer = :customer
)
)
)

我得到的是以下内容:

org.hibernate.util.StringHelper.root(StringHelper.java:257)

Caused by: java.lang.NullPointerException
at org.hibernate.util.StringHelper.root(StringHelper.java:257)
at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber(AbstractEntityPersister.java:1391)
at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:54)
at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1367)
at org.hibernate.hql.ast.tree.FromElement.getIdentityColumn(FromElement.java:320)
at org.hibernate.hql.ast.tree.IdentNode.resolveAsAlias(IdentNode.java:154)
at org.hibernate.hql.ast.tree.IdentNode.resolve(IdentNode.java:100)
at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:117)
at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:113)
at org.hibernate.hql.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:854)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.propertyRef(HqlSqlBaseWalker.java:1172)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.propertyRefLhs(HqlSqlBaseWalker.java:5167)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.propertyRef(HqlSqlBaseWalker.java:1133)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:1993)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:1932)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1476)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:580)
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.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:484)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:394)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341)

使用:Hibernate 3.3.2.GA/postgresql


更新:

我试图通过尝试为自己执行每个子条款来隔离错误。我发现我通过执行得到了同样的异常:

select enty.number from EntityAliasName enty

但是如果我执行以下它会起作用:

select number from EntityAliasName enty

那么现在的问题是,为什么?

也许我应该提到 EntityAliasName 是通过以下方式定义的实体别名:

<class name="package.EntityName"
table="entities"
entity-name="EntityAliasName"
mutable="false"> ... </class>

更新 2:

我找到了解决问题的方法。我的 POJO 是这样映射的:

<class name="package.EntityName"
table="entities"
entity-name="EntityAliasName"
mutable="false">

<composite-id>
<key-property name="val1" column="val1" type="long"/>
<key-property name="val2" column="val2" type="integer"/>
</composite-id>

<property name="id" column="entity_id" type="string" length="255" not-null="true"/>

...

</class>

在使用复合 ID 和使用名为 id 的属性时出现问题:HHH-1851报告人 Anthony Patricio .将属性名称从 id 更改为 entityId 解决了这个问题:

感谢mdma为我指明了正确的方向。

最佳答案

我找到了解决问题的方法。我的 POJO 是这样映射的:

<class name="package.EntityName"
table="entities"
entity-name="EntityAliasName"
mutable="false">

<composite-id>
<key-property name="val1" column="val1" type="long"/>
<key-property name="val2" column="val2" type="integer"/>
</composite-id>

<property name="id" column="entity_id" type="string" length="255" not-null="true"/>

...

</class>

在使用复合 ID 和使用名为 id 的属性时出现问题:HHH-1851报告人 Anthony Patricio .将属性名称从 id 更改为 entityId 解决了这个问题:

<property name="entityId" column="entity_id" 
type="string" length="255" not-null="true"/>

感谢mdma为我指明了正确的方向。

刚刚从我上面的更新中复制了答案,作为回答关闭它并保持接受率

关于java - 这个 HQL 查询有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2849447/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com