0 Replies Latest reply on Jul 23, 2010 9:19 PM by Dave Chen

    HQL fails after obfuscation, DetachedCriteria OK

    Dave Chen Master

      Hi,
      I use JBoss 5.1 that uses Hibernate core 3.3.1 and EntityManager 3.4.0.

       

      I tried to use proguard to obfuscate entity class names. For example,

       

      @Entity(name="Foo")
      class Foo --> f

       

      @Entity(name="Bar")
      class Bar --> g

       

      NamedQuery:
      select a from Foo a, Bar b where ....

       

      org.hibernate.hql.ast.QuerySyntaxException: ??? is not mapped.
      From debug, the query string is correctly passed to Hibernate. where the three question marks come from? Thanks for help.

       

      at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)
      at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110)
      at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93)
      at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:277)
      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.selectStatement(HqlSqlBaseWalker.java:281)
      at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
      at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:251)
      at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
      at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:134)
      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:436)
      at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:384)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
      at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
      at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)

       

      ----------

       

      I tried the following again:

       

      package mypackage;

       

      @Entity(name="Student")
      @Table(name="Student")
      class Student {
      age,
      name
      }

       

      HQL:
      select distinct c from Student c where c.age>=20 order by c.name desc

       

      It works fine.

       

      After obfuscation, the Student class name becomes a;
      (From the following error message). The entity name and table name is not changed.

       

      Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: ??? is not mapped [select distinct c from mypackage.a c where c.age>=20 order by c.name desc]

       

      The mesage should let me know which is not mapped, but it shows question marks.

       

      DetachedCriteria works fine before and after obfuscation.

       

      Thanks for help. any ideas are appreciated.

       

      Dave