0

我想加载吸烟者并被诊断出心跳高于 120。我不断收到此错误 org.hibernate.Query 无法解决财产吸烟问题。如果我将属性更改为其他 fe id,我会收到相同的错误。我尝试了不同的查询,结果相同。所有实体都在单独的文件中。我的代码有什么问题?

询问:

Query q = em.createQuery("select p from Patient p join p.visits v join v.data d WHERE d.smoking = 'yes' and d.heartrate > 120");

代码:

import javax.persistence.Query;
[...]

@Entity
public class Patient extends Person implements Serializable {
     private static final long serialVersionUID = 1L;
     private int id;
     @OneToMany
     private List<Visit> visits = new ArrayList<>();
[...]
}
@Entity
public class Visit implements Serializable {
     private static final long serialVersionUID = 1L;
     private int id;
     @OneToOne
     private Data data;
[...]
}
@Entity
public class Data implements Serializable {
     private static final long serialVersionUID = 1L;
     private int id;
     private String smoking;
     private int heartrate;
[...]
}

堆栈跟踪:

java.lang.IllegalArgumentException: org.hibernate.QueryException: could not resolve property: palacy  of: odwzorowania.Wywiad [select p from odwzorowania.Pacjent p join p.wizyty w join w.wywiad wy WHERE wy.palacy = 'tak' AND wy.tetno > 120]
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:624)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:96)
at ntbd.Przychodnia.jButtonZnajdzPacjentowTetnoActionPerformed(Przychodnia.java:904)
at ntbd.Przychodnia.access$1100(Przychodnia.java:23)
at ntbd.Przychodnia$18.actionPerformed(Przychodnia.java:682)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2713)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:680)
at java.awt.EventQueue$4.run(EventQueue.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: org.hibernate.QueryException: could not resolve property: palacy  of: odwzorowania.Wywiad [select p from odwzorowania.Pacjent p join p.wizyty w join w.wywiad wy WHERE wy.palacy = 'tak' AND wy.tetno > 120]
    at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:44)
    at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:38)
    at org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1358)
    at org.hibernate.hql.ast.tree.FromElementType.getPropertyType(FromElementType.java:279)
    at org.hibernate.hql.ast.tree.FromElement.getPropertyType(FromElement.java:386)
    at org.hibernate.hql.ast.tree.DotNode.getDataType(DotNode.java:566)
    at org.hibernate.hql.ast.tree.DotNode.prepareLhs(DotNode.java:241)
    at org.hibernate.hql.ast.tree.DotNode.resolve(DotNode.java:188)
    at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:94)
    at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:90)
    at org.hibernate.hql.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:728)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1216)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4041)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3525)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1762)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1687)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:776)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:577)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
    at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
    at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
    at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
    at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
    at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
    at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
    at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
    at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:93)
    ... 39 more
4

1 回答 1

4

请注意,您的查询包含U+3000 IDEOGRAPHIC SPACE而不是常规空格:

... WHERE wy.palacy = 'tak' AND wy.tetno > 120
                   ^ here

Hibernate 将其视为属性名称的一部分。

于 2013-01-19T20:10:21.443 回答