-->
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: QueryTranslator problem
PostPosted: Fri Feb 18, 2005 7:29 pm 
Newbie

Joined: Fri Feb 18, 2005 7:14 pm
Posts: 5
Location: State College, PA
Hibernate version:
2.1

Mapping documents:
Code:
<hibernate-mapping package="org.dm.daniel.grace.storage">

   <class name="ContactInfo" table="contact_info">

      <!-- id field -->
      <id name="id" column="id" type="long" unsaved-value="null">
           <generator class="native"/>
        </id>

      <!-- Properties -->
        <property name="addr1" type="text"/>
        <property name="addr2" type="text"/>
        <property name="city" type="text"/>
        <property name="state" type="text"/>
        <property name="zip" type="text"/>
        <property name="country" type="text"/>
        <property name="phone" type="text"/>
        <property name="email" type="text"/>
       
        <!-- Associations -->
      
      <!-- Subclasses -->
      
    </class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
I'm using Spring, but here it is anyway:
Code:
  String zip5 = "12345";
  List zips = getHibernateTemplate().find(
    "  FROM ContactInfo AS ci" +
    " WHERE ci.zip LIKE ?" +
    " ORDER BY ci.zip" + /* (1) */
    " LIMIT 1",
    zip5, Hibernate.STRING);


Full stack trace of any exception that occurs:
Code:
18:05:58,032 FATAL [FrameworkAction] Fatal error: Problem accessing application server; Caused by: org.springframework.jdbc.BadSqlGrammarException: Bad SQL grammar [] in task 'Hibernate operation'; nested exception is java.sql.SQLException: You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 1 )' at line 1
java.sql.SQLException: You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 1 )' at line 1
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2851)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1534)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1625)
   at com.mysql.jdbc.Connection.execSQL(Connection.java:2297)
   at com.mysql.jdbc.Connection.execSQL(Connection.java:2226)
   at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1812)
   at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1657)
   at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:88)
   at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
   at net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
   at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
   at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
   at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
   at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1553)
   at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
   at org.springframework.orm.hibernate.HibernateTemplate$24.doInHibernate(HibernateTemplate.java:521)
   at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:243)
   at org.springframework.orm.hibernate.HibernateTemplate.executeFind(HibernateTemplate.java:263)
   at org.springframework.orm.hibernate.HibernateTemplate.find(HibernateTemplate.java:512)
   at org.dm.daniel.grace.business.UtilManagerImpl.getCityStateFromZip(UtilManagerImpl.java:158)
   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:585)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:296)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:155)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
   at org.springframework.orm.hibernate.HibernateInterceptor.invoke(HibernateInterceptor.java:163)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:56)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
   at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:80)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
   at $Proxy52.getCityStateFromZip(Unknown Source)
   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:585)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:296)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:163)
   at $Proxy52.getCityStateFromZip(Unknown Source)
   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:585)
   at org.springframework.remoting.support.RemoteInvocation.invoke(RemoteInvocation.java:179)
   at org.springframework.remoting.support.DefaultRemoteInvocationExecutor.invoke(DefaultRemoteInvocationExecutor.java:32)
   at org.springframework.remoting.support.RemoteInvocationBasedExporter.invoke(RemoteInvocationBasedExporter.java:70)
   at org.springframework.remoting.support.RemoteInvocationBasedExporter.invokeAndCreateResult(RemoteInvocationBasedExporter.java:106)
   at org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter.handleRequest(HttpInvokerServiceExporter.java:69)
   at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:584)
   at org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:368)
   at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:328)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at net.sf.acegisecurity.ui.AbstractIntegrationFilter.doFilter(AbstractIntegrationFilter.java:170)
   at net.sf.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:105)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at net.sf.acegisecurity.ui.basicauth.BasicProcessingFilter.doFilter(BasicProcessingFilter.java:199)
   at net.sf.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:105)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:731)
   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
   at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
   at java.lang.Thread.run(Thread.java:595)



Name and version of the database you are using:
MySQL 4.0.23

The generated SQL (show_sql=true):
CASE 1: select contactinf0_.id as id, contactinf0_.addr1 as addr1, contactinf0_.addr2 as addr2, contactinf0_.city as city, contactinf0_.state as state, contactinf0_.zip as zip, contactinf0_.country as country, contactinf0_.phone as phone, contactinf0_.email as email from contact_info contactinf0_ where (contactinf0_.zip LIKE ? LIMIT 1 )

CASE 2: select contactinf0_.id as id, contactinf0_.addr1 as addr1, contactinf0_.addr2 as addr2, contactinf0_.city as city, contactinf0_.state as state, contactinf0_.zip as zip, contactinf0_.country as country, contactinf0_.phone as phone, contactinf0_.email as email from contact_info contactinf0_ where (contactinf0_.zip LIKE ? ) order by contactinf0_.zip LIMIT 1


Debug level Hibernate log excerpt:
(I'll spare you, unless you really want it!) =)

Anyhow, note that there are two cases for the generated SQL. The second one works, while the first one does not, and it throws an exception. (Quickly, it's because the LIMIT field is inside the parentheses.)

Note in my code the line marked with the /* (1) */. If that line is removed, I get CASE 1. That is, The QueryTranslator doesn't seem to understand it. If I add an ORDER BY, however, things seem to work okay, and I get CASE 2.

So, perhaps this is a HQL translation bug. But perhaps I'm doing something wrong. I figured I'd post here before filing a bug. What do you think?


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.