-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: QueryBuilder intermittently creates invalid query
PostPosted: Wed Jul 31, 2013 4:28 am 
Newbie

Joined: Wed Jul 31, 2013 4:09 am
Posts: 1
I have several classes that use query builder to generate queries. At least one of these fails intermittently when the query creates a new generated alias in the where clause when the original object is being used for arguments in the builder. I think this is a QueryBuilder issue but want to know if anyone else has seen this problem.

The error I receive is

Code:
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Invalid path: 'generatedAlias1.bundle' [select generatedAlias0 from com.synchronoss.readytogo.dao.DrbBundleBeanImpl as generatedAlias0 where generatedAlias1.bundle=:param0]
   at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
   at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
   at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:79) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
   at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:255) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
   at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
   at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
   at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:105) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
   at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
   at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
   at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:216) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
   at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:194) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
   at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1736) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
   at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:493) [hibernate-entitymanager-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]


The code that generates the query is:

Code:
class Foo {
...
private  CriteriaQuery<DrbBundleBeanImpl> beansQuery;
...
private CriteriaQuery<DrbBundleBeanImpl> getBeansQuery()
   {
      if(beansQuery == null)
      {
      CriteriaBuilder builder = manager.getCriteriaBuilder();

      builder = manager.getCriteriaBuilder();
      beansQuery = builder.createQuery(DrbBundleBeanImpl.class);
      Root<DrbBundleBeanImpl> root = beansQuery.from( DrbBundleBeanImpl.class );
      beansQuery.where(builder.equal(root.<String>get("bundle"),
                 builder.parameter(String.class, "param")));
      }
      return beansQuery;
   }
...
}


The bean implementation code:

Code:

@Entity(name="DrbBundleBean")
@Table( name="SNCR_DRB_BUNDLE")
@IdClass(DrbBundleBeanImpl.PK.class)
public class DrbBundleBeanImpl implements DrbBundleBean {

   /**
    *
    */
   private static final long serialVersionUID = 1L;
   @Id
    private String bundle;
    @Id
    private String locale;
    @Id
    @Column(name="KEY_NAME")
    private String key;

    private String value;

   public String getBundle() {
      return bundle;
   }

   public void setBundle(String bundle) {
      this.bundle = bundle;
   }

   public String getLocale() {
      return locale;
   }

   public void setLocale(String locale) {
      this.locale = locale;
   }

   public String getKey() {
      return key;
   }

   public void setKey(String key) {
      this.key = key;
   }

   public String getValue() {
      return value;
   }

   public void setValue(String value) {
      this.value = value;
   }

   /**
    * The primary key for the bundle bean
    *
    */
   public static class PK implements Serializable {
      private static final long serialVersionUID = 2697712362067232634L;
      private String bundle;
       private String locale;
       private String key;

       public PK(){
       }
      
       public PK(DrbBundleBean bean){
           this.bundle = bean.getBundle();
           this.locale = bean.getLocale();
           this.key = bean.getKey();
       }
      
       public String getBundle() {
           return bundle;
       }

       public void setBundle(String bundle) {
           this.bundle = bundle;
       }

       public String getLocale() {
           return locale;
       }

       public void setLocale(String locale) {
           this.locale = locale;
       }

       public String getKey() {
           return key;
       }

       public void setKey(String key) {
           this.key = key;
       }
      
       public boolean equals(Object o)
       {
          if (o instanceof PK)
          {
             PK pk2 = (PK)o;
             return new EqualsBuilder().append( getBundle(), pk2.getBundle() )
                   .append( getLocale(), pk2.getLocale() )
                   .append( getKey(), pk2.getKey() ).isEquals();   
          }
          return false;
       }
      
       public int hashCode()
       {
          return new HashCodeBuilder().append( getBundle() ).append( getLocale() ).append( getKey() ).toHashCode();
       }
      
   }
   
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.