-->
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.  [ 4 posts ] 
Author Message
 Post subject: Criteria Query throws SQLGrammarException
PostPosted: Sun Nov 26, 2006 5:23 pm 
Regular
Regular

Joined: Wed Nov 01, 2006 2:17 pm
Posts: 78
Hi,

I'm doing some Criteria query:

Code:
      (List<Group>) getSession().createCriteria(Group.class)
      .addOrder( Order.asc("name") )
      .list();


The SQL (HQL?) generated is the following, I think the last word "this_" isn't right, is it?

Hibernate: select this_.id as id0_0_, this_.version as version0_0_, this_.name as name0_0_, this_.description as descript4_0_0_ from Group this_

Why does Hibernate produce this wrong statement?

Attached is the exception I got: "SQLGrammarException".

Please help me ... what is wrong?

Hibernate version: 3

Mapping documents:
<hibernate-mapping package="de.tfhberlin.eclipsophone.server.beans" auto-import="true">
<class name="Group" table="Group" lazy="false">
<id name="id" column="id" type="long" unsaved-value="0">
<generator class="native" />
</id>
<version name="version" column="version" unsaved-value="negative"/>
<property name="name" column="name" type="string" />
<property name="description" column="description" type="string" />
<set name="participating_users" table="UserGroup">
<key column="group_id" />
<many-to-many column="user_id" class="User" />
</set>
</class>
</hibernate-mapping>

Full stack trace of any exception that occurs:
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2148)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1533)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at de.tfhberlin.eclipsophone.server.daos.HibernateGroupDAO.getAll(HibernateGroupDAO.java:22)
at de.tfhberlin.eclipsophone.server.logic.GroupManagerImpl.getAll(GroupManagerImpl.java:23)
at de.tfhberlin.eclipsophone.server.webapp.controllers.AjaxGroupsController.handleRequest(AjaxGroupsController.java:25)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:45)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:806)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:736)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:396)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:350)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:264)
at org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:107)
at org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:72)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:110)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:217)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:229)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:148)
at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
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:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
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(Unknown Source)

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

The generated SQL (show_sql=true):
Hibernate: select this_.id as id0_0_, this_.version as version0_0_, this_.name as name0_0_, this_.description as descript4_0_0_ from Group this_


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 27, 2006 1:59 am 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
Thats weird that the query you refer to has no "order by" since the criteria line has an order by. Anyways, make sure the mapping is correct, and the column names are spelled correctly etc. Run that query directly in MySQL and see that you get the same error. this_ shouldnt be the problem, its just an alias.

Chris


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 27, 2006 6:05 am 
Regular
Regular

Joined: Wed Nov 01, 2006 2:17 pm
Posts: 78
mchyzer wrote:
Thats weird that the query you refer to has no "order by" since the criteria line has an order by. Anyways, make sure the mapping is correct, and the column names are spelled correctly etc. Run that query directly in MySQL and see that you get the same error. this_ shouldnt be the problem, its just an alias.

Chris


Sorry, my fault. I commented out the ORDER-clause. The error still remains. I checked my mapping file but everything seems to be correct. This is my database table Group:

Image


EDIT: I think it could be the name "Group" of the table .. this is a keyword ... I will check it.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 27, 2006 6:29 am 
Regular
Regular

Joined: Wed Nov 01, 2006 2:17 pm
Posts: 78
This is it: Group is a keyword. I changed the name of the table to antoher one.

Thanks.


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

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.