3 Replies Latest reply on Apr 10, 2006 2:06 PM by keenan

    QuerySyntaxException: this makes no sense...

      I'm doing the simplest of queries and I'm getting an exception...I'm thoroughly stumped on this one.

      I'm building a simple blogger app w/ EJB3 & Wicket as a proof-of-concept to see how stable JBoss EJB3 is and if I'll be able to use it in production applications (I know people are doing this now but I'd like to see it for myself.)

      I'm using JBoss 4.0.4RC1 on Gentoo Linux. My database is PostgreSQL 8.0 using the official PostgreSQL 8.0 JDBC driver.

      Anyhow, this should be pretty straightforward:

      I have a Blog entity:

      @Entity
      @Table(name="tbl_blog")
      public class Blog implements Serializable
      {
       private int id;
       private String name;
       private String synopsis;
       private String description;
       private Date dateCreated;
       private boolean isDefault;
       private List<Category> categories;
       private List<Entry> entries;
      
       public Blog()
       {
       }
      
       public Date getDateCreated()
       {
       return this.dateCreated;
       }
      
       public void setDateCreated(Date dateCreated)
       {
       this.dateCreated = dateCreated;
       }
      
       @NotNull @Length(max=100)
       public String getDescription()
       {
       return this.description;
       }
      
       public void setDescription(String description)
       {
       this.description = description;
       }
      
       @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
       public int getId()
       {
       return this.id;
       }
      
       public void setId(int id)
       {
       this.id = id;
       }
      
       public boolean getIsDefault()
       {
       return this.isDefault;
       }
      
       public void setIsDefault(boolean isDefault)
       {
       this.isDefault = isDefault;
       }
      
       @NotNull @Length(max=50)
       public String getName()
       {
       return this.name;
       }
      
       public void setName(String name)
       {
       this.name = name;
       }
      
       @NotNull @Length(max=100)
       public String getSynopsis()
       {
       return this.synopsis;
       }
      
       public void setSynopsis(String synopsis)
       {
       this.synopsis = synopsis;
       }
      
       @OneToMany(mappedBy="category",fetch=FetchType.LAZY)
       public List<Category> getCategories()
       {
       return this.categories;
       }
      
       public void setCategories(List<Category> categories)
       {
       this.categories = categories;
       }
      
       @Transient
       public List<Entry> getEntries()
       {
       return this.entries;
       }
      
       public void setEntries(List<Entry> entries)
       {
       this.entries = entries;
       }
      }
      


      I call it like so:

       public Blog getDefault()
       {
       Blog blog = null;
      
       //http://opensource2.atlassian.com/projects/hibernate/browse/EJB-133
       try //TODO: BUG IN JBOSS EJB3 - remove NoResultException in final release!
       {
       Query q = this.em.createQuery("select b from Blog b where b.isDefault");
       blog = (Blog)q.getSingleResult();
       }
       catch (NoResultException exp)
       {
       blog = null;
       }
      
       return blog;
       }
      


      I get the following exception:

      19:17:38,092 ERROR [PARSER] <AST>:1:56: unexpected AST node: .
      19:17:38,122 ERROR [RequestCycle] org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: . near line 1, column 56 [select b from com.myapp.model.Blog b where b.isDefault]
      javax.ejb.EJBException: org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: . near line 1, column 56 [select b from com.myapp.model.Blog b where b.isDefault]
       at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
       at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:192)
      ...............
      
      Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: . near line 1, column 56 [select b from com.myapp.model.Blog b where b.isDefault]
       at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
       at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:225)
       at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:158)
       at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109)
       at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75)
       at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
      .............
      
      Caused by: <AST>:1:56: unexpected AST node: .
       at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1766)
       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:218)
       ... 79 more
      


      To be clear, there's a record in the table...which was inserted using EJB3 in a setup class I created to test EJB3 inserts via persist()...which also served to pre-populate the db w/ some test data for me.

      ...if I query it directly in psql:

      speakup=# select * from tbl_blog;
       id | name | description | datecreated | isdefault | synopsis
      ----+----------+--------------+-------------------------+-----------+--------------------------------
       1 | myblog | default blog | 2006-04-09 12:39:02.118 | f | I'm just testing...
      (1 row)
      


      I sifted through the log but couldn't find any indication of the problem...though I do see this:

      .....
      2006-04-09 19:17:37,873 DEBUG [org.hibernate.hql.ast.QueryTranslatorImpl] parse() - HQL: select b from com.myapp.model.Blog b where b.isDefault
      2006-04-09 19:17:37,898 DEBUG [org.hibernate.hql.ast.AST] --- HQL AST ---
       \-[QUERY] 'query'
       +-[SELECT_FROM] 'SELECT_FROM'
       | +-[FROM] 'from'
       | | \-[RANGE] 'RANGE'
       | | +-[DOT] '.'
       | | | +-[DOT] '.'
       | | | | +-[DOT] '.'
       | | | | | +-[DOT] '.'
       | | | | | | +-[IDENT] 'com'
       | | | | | | \-[IDENT] 'myapp'
       | | | | | \-[IDENT] 'model'
       | | | \-[IDENT] 'Blog'
       | | \-[ALIAS] 'b'
       | \-[SELECT] 'select'
       | \-[IDENT] 'b'
       \-[WHERE] 'where'
       \-[DOT] '.'
       +-[IDENT] 'b'
       \-[IDENT] 'isDefault'
      
      2006-04-09 19:17:37,898 DEBUG [org.hibernate.hql.ast.ErrorCounter] throwQueryException() : no errors
      2006-04-09 19:17:38,032 DEBUG [org.hibernate.hql.antlr.HqlSqlBaseWalker] select << begin [level=1, statement=select]
      2006-04-09 19:17:38,078 DEBUG [org.hibernate.hql.ast.tree.FromElement] FromClause{level=1} : com.myapp.model.Blog (b) -> blog0_
      2006-04-09 19:17:38,079 DEBUG [org.hibernate.hql.ast.tree.FromReferenceNode] Resolved : b -> blog0_.id
      2006-04-09 19:17:38,092 ERROR [org.hibernate.hql.PARSER] <AST>:1:56: unexpected AST node: .
      2006-04-09 19:17:38,092 DEBUG [org.hibernate.hql.ast.ErrorCounter] <AST>:1:56: unexpected AST node: .
      <AST>:1:56: unexpected AST node: .
      ......
      


      Is there a problem w/ Postgres & EJB3 or am I doing something wrong?

      Thanks!