hql - 获取意外令牌的错误

时间:2014-08-19 10:06:47

标签: java hibernate hql

我正在使用Hibernate,我有这个查询:

  

列表list = session.createQuery("来自项目项目所在的位置   project.properties.pr_id =' 4711' ")列表();

和Project的这个hbm文件:

<hibernate-mapping auto-import="true">
  <class dynamic-insert="true" dynamic-update="true" entity-name="Project" name="de.planta.server.hibernate.pojo.DynamicPojo" table="DT461">
  <dynamic-component name="properties">
   <property column="`DI041544`" default="0" name="miscel_pay_oblig" type="de.planta.server.hibernate.types.DefaultValueDoubleType" /> 
   <property column="`DI051881`" length="10" name="report_pls_report_id" type="de.planta.server.hibernate.types.DefaultValueStringType" /> 
   <property column="`DI059017`" length="8" name="active_process_phase" type="de.planta.server.hibernate.types.DefaultValueStringType" /> 
   <property column="`DI001001`" length="18" name="pr_id" type="de.planta.server.hibernate.types.DefaultValueStringType" />
         ...  

和这个错误信息,但为什么???

14:51:44.157 ERROR  session=33 o.h.hql.internal.ast.ErrorCounter - line 1:23: unexpected token: p
14:51:44.158 ERROR  session=33 o.h.hql.internal.ast.ErrorCounter - line 1:23: unexpected token: p
antlr.NoViableAltException: unexpected token: p
        at org.hibernate.hql.internal.antlr.HqlBaseParser.atom(HqlBaseParser.java:3716) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
        at org.hibernate.hql.internal.antlr.HqlBaseParser.unaryExpression(HqlBaseParser.java:3376) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
        at org.hibernate.hql.internal.antlr.HqlBaseParser.multiplyExpression(HqlBaseParser.java:3248) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
        at org.hibernate.hql.internal.antlr.HqlBaseParser.additiveExpression(HqlBaseParser.java:2954) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
        at org.hibernate.hql.internal.antlr.HqlBaseParser.concatenation(HqlBaseParser.java:590) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
        at org.hibernate.hql.internal.antlr.HqlBaseParser.relationalExpression(HqlBaseParser.java:2721) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
        at org.hibernate.hql.internal.antlr.HqlBaseParser.equalityExpression(HqlBaseParser.java:2582) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
        at org.hibernate.hql.internal.antlr.HqlBaseParser.negatedExpression(HqlBaseParser.java:2546) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
        at org.hibernate.hql.internal.antlr.HqlBaseParser.logicalAndExpression(HqlBaseParser.java:2462) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
        at org.hibernate.hql.internal.antlr.HqlBaseParser.logicalOrExpression(HqlBaseParser.java:2427) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
        at org.hibernate.hql.internal.antlr.HqlBaseParser.expression(HqlBaseParser.java:2137) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
        at org.hibernate.hql.internal.antlr.HqlBaseParser.logicalExpression(HqlBaseParser.java:1913) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
        at org.hibernate.hql.internal.antlr.HqlBaseParser.whereClause(HqlBaseParser.java:474) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
        at org.hibernate.hql.internal.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:729) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
        at org.hibernate.hql.internal.antlr.HqlBaseParser.selectStatement(HqlBaseParser.java:316) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
        at org.hibernate.hql.internal.antlr.HqlBaseParser.statement(HqlBaseParser.java:179) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
        at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:295) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
        at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:203) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
        at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
        at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:126) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
        at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:88) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
        at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:190) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
        at de.planta.server.hibernate.PlantaSession.getHQLQueryPlan(PlantaSession.java:180) [PlantaServer.jar:na]
        at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
        at de.planta.server.hibernate.PlantaSession.createQuery(PlantaSession.java:172) [PlantaServer.jar:na]
        at de.planta.server.hibernate.SessionHandler.createQuery(SessionHandler.java:177) [PlantaServer.jar:na]
        at de.planta.server.hibernate.NativeHQLEnversInterface.hqlQuery(NativeHQLEnversInterface.java:71) [PlantaServer.jar:na]
        at de.planta.server.hibernate.NativeHQLEnversInterface.hqlQuery(NativeHQLEnversInterface.java:103) [PlantaServer.jar:na]
        at de.planta.server.NativeInterface.startThread(Native Method) [PlantaServer.jar:na]
        at de.planta.server.threads.PlantaServerThread.run(PlantaServerThread.java:146) [PlantaServer.jar:na]
Exception in thread "PlantaSession" org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: p near line 1, column 23 [ From Project p where p.properties.pr_id = '4711' ]
        at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:91)
        at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:109)
        at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:304)
        at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:203)
        at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158)
        at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:126)
        at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:88)
        at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:190)
        at de.planta.server.hibernate.PlantaSession.getHQLQueryPlan(PlantaSession.java:180)
        at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236)
        at de.planta.server.hibernate.PlantaSession.createQuery(PlantaSession.java:172)
        at de.planta.server.hibernate.SessionHandler.createQuery(SessionHandler.java:177)
        at de.planta.server.hibernate.NativeHQLEnversInterface.hqlQuery(NativeHQLEnversInterface.java:71)
        at de.planta.server.hibernate.NativeHQLEnversInterface.hqlQuery(NativeHQLEnversInterface.java:103)
        at de.planta.server.NativeInterface.startThread(Native Method)
        at de.planta.server.threads.PlantaServerThread.run(PlantaServerThread.java:146)

PojoClass

public class DynamicPojo extends HibernatePojoClass {
    private static final long serialVersionUID = 7906434537945052481L;

    @Id
    @GeneratedValue
    @NotNull
    private UUID id;

    private Map<String,Object> properties = new HashMap<String, Object>();
    private Map<String,Object> formulaProperties = new HashMap<String, Object>();

    @Override
    @Audited
    public UUID getId() {
        return id;
    }

    @Override
    public void setId(UUID id) {
        this.id = id;
    }

    @Override
    @Audited
    public Map<String, Object> getProperties() {
        return properties;
    }

    @Override
    public void setProperties(Map<String, Object> properties) {
        this.properties = properties;
    } 
    ...

1 个答案:

答案 0 :(得分:0)

我用以下错误修正错误:

<property name="hibernate.query.factory_class">org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory</property>

但我不知道为什么? 有谁能解释一下?