-->
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: Parsing Problem with AST or classic factory
PostPosted: Wed Mar 17, 2010 6:00 am 
Newbie

Joined: Tue Mar 16, 2010 1:35 pm
Posts: 1
I have an parsing error and i would like to know if anybody had already this problem.

Libraries used for hibernate :
hibernate-core 3.3.2.GA
hibernate-annotations 3.4.0.GA
net.sf.ehcache 1.6.2
slf4j-log4j12 1.5.10
javassist 3.9.0.GA
cglib 2.2
antlr 2.7.6
dom4j 1.6.1

Entity « Courriel »:
Code:
@Entity
@Table(name = "COURRIEL")
public class Courriel implements java.io.Serializable {

       private static final long serialVersionUID = 1L;
   private int oid;
   private String adresse;

       @SequenceGenerator(name = "generator", sequenceName = "myseq_courriel")
   @Id
   @GeneratedValue(strategy = SEQUENCE, generator = "generator")
   @Column(name = "OID", nullable = false)
   public int getOid() { return this.oid; }
   public void setOid(int oid) { this.oid = oid; }

   @Column(name = "ADRESSE")
   public String getAdresse() { return this.adresse; }
   public void setAdresse(String adresse) { this.adresse = adresse; }
}

SpringContext :
Code:
<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      <property name="annotatedClasses">
      <list>
         <value>gouv.education.ramsese.uai.Courriel</value>
      </list>
      </property>
      <property name="hibernateProperties">
         <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect</prop>
            <prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</prop>
              </props>
      </property>
      <property name="dataSource" ref="dataSource"/> <!-- retrieve by JNDI / or BasicDataSource-->
   </bean>

   <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
      <property name="sessionFactory" ref="mySessionFactory"/>
   </bean>


Unit Test via AbstractDependencyInjectionSpringContextTests :
Code:
// SpringContext Loaded by AbstractDependencyInjectionSpringContextTests in class HibernateUnitTest
public class HibernateTest extends HibernateUnitTest {   
   private HibernateTemplate hibernateTemplate;
   public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
      this.hibernateTemplate = hibernateTemplate;
   }

   @SuppressWarnings("unchecked")
   public void testHQLCast() {
      StringBuilder hqlQuery = new StringBuilder("select cast(c.oid as varchar(100)) from Courriel c");
      Session session = hibernateTemplate.getSessionFactory().getCurrentSession();
      Query query = session.createQuery(hqlQuery.toString());
      List<String> list = query.list();      
      assertFalse(list.isEmpty());      
   }   
}




Configuration 1:

Dialect: org.hibernate.dialect.DB2Dialect
QueryTranslatorFactory: org.hibernate.hql.classic.ClassicQueryTranslatorFactory (Old Factory)


Parsing error: A concatenate is realized at HQL : cast(c.oid as varchar(100)) -> SQL : l0_.OIDasvarchar(100


Code:
org.hibernate.exception.SQLGrammarException: could not execute query
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
   at org.hibernate.loader.Loader.doList(Loader.java:2235)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)
   at org.hibernate.loader.Loader.list(Loader.java:2124)
   at org.hibernate.hql.classic.QueryTranslatorImpl.list(QueryTranslatorImpl.java:935)
   at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1149)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
   at gouv.education.ramsese.test.HibernateTest.testHQLCast(HibernateTest.java:106)
Caused by: com.ibm.db2.jcc.a.ho: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=);l0_.OIDasvarchar(100;<space>, DRIVER=4.3.85



Configuration 2:

Dialect: org.hibernate.dialect.DB2Dialect
QueryTranslatorFactory: org.hibernate.hql.ast.ASTQueryTranslatorFactory (Default Factory in hibernate 3.3.2.GA)


Parsing error: The cast function is not parsing correctly :

Code:
org.hibernate.hql.ast.QuerySyntaxException: expecting CLOSE, found '(' near line 1, column 29 [select cast(c.oid as varchar(100)) from gouv.education.ramsese.uai.Courriel c]
   at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
   at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
   at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
   at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:284)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:182)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
   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.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
   at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
   at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1651)
   at gouv.education.ramsese.test.HibernateTest.testHQLCast(HibernateTest.java:105)
)



Code:
Configuration 1bis
:

Code:
Dialect:
org.hibernate.dialect.DB2Dialect
Code:
QueryTranslatorFactory:
org.hibernate.hql.classic.ClassicQueryTranslatorFactory (Old Factory)

Code:
   @SuppressWarnings("unchecked")
   public void testHQLCastWhere() {
      StringBuilder hqlQuery = new StringBuilder("select c.libelle from Courriel c where c.adresse =  cast(? as varchar(100))");
      Session session = hibernateTemplate.getSessionFactory().getCurrentSession();
      Query query = session.createQuery(hqlQuery.toString());
      query.setString(0, "test@test.com");
      List<String> list = query.list();      
      assertFalse(list.isEmpty());      
   }


Or

Code:
   @SuppressWarnings("unchecked")
   public void testHQLCastWhere() {
      StringBuilder hqlQuery = new StringBuilder("select c.libelle from Courriel c where c.adresse =  cast('test@test.com' as varchar(100))");
      Session session = hibernateTemplate.getSessionFactory().getCurrentSession();
      Query query = session.createQuery(hqlQuery.toString());
      List<String> list = query.list();      
      assertFalse(list.isEmpty());      
   }   


These tests are OK!


Code:
Configuration 2bis:


Code:
Dialect
: org.hibernate.dialect.DB2Dialect
Code:
QueryTranslatorFactory
: org.hibernate.hql.ast.ASTQueryTranslatorFactory (Default Factory in hibernate 3.3.2.GA)

Code:
   @SuppressWarnings("unchecked")
   public void testHQLCastWhere() {
      StringBuilder hqlQuery = new StringBuilder("select c.libelle from Courriel c where c.adresse =  cast('test@test.com' as varchar(100))");
      Session session = hibernateTemplate.getSessionFactory().getCurrentSession();
      Query query = session.createQuery(hqlQuery.toString());
      List<String> list = query.list();      
      assertFalse(list.isEmpty());      
   }   


or
Code:
   @SuppressWarnings("unchecked")
   public void testHQLCastWhere() {
      StringBuilder hqlQuery = new StringBuilder("select c.libelle from Courriel c where c.adresse =  cast(? as varchar(100))");
      Session session = hibernateTemplate.getSessionFactory().getCurrentSession();
      Query query = session.createQuery(hqlQuery.toString());
      query.setString(0, "test@test.com");
      List<String> list = query.list();      
      assertFalse(list.isEmpty());      
   }


These tests are in error :
Code:
org.hibernate.hql.ast.QuerySyntaxException: expecting CLOSE, found '(' near line 1, column 111 [select c.libelle from gouv.education.ramsese.uai.Courriel c where c.adresse =  cast('test@test.com' as varchar(100))]
   at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
   at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
   at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
   at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:284)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:182)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
   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.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
   at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
   at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1651)
   at gouv.education.ramsese.test.HibernateTest.testHQLCastWhere(HibernateTest.java:114)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at junit.framework.TestCase.runTest(TestCase.java:164)
   at junit.framework.TestCase.runBare(TestCase.java:130)
   at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:79)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:120)
   at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


What's wrong ?


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.