-->
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: SQLGrammarException bei Criteria-Benutzung
PostPosted: Sun Nov 26, 2006 10:09 am 
Regular
Regular

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

seit kurzem habe ich diese SQLGrammarException. Ich hab einfachnochmal in Eclipse das Projekt neu aufgemacht und meine Tabellen in der Datenbank umbenannt. Habe jeweils das s weggenommen. Also z.B. "User" anstatt "Users". Die Mappingdateien habe ich demenstprechend angepasst.

Bei Ausführung des folgenden Criteria-Kommandos erhalte ich die Exception:

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


Sieht ganz simpel aus und hat auch schonmal funktioniert .... aber warum geht das jetzt nicht mehr?

Hibernate version: 3

Mapping documents:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<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.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:408)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:350)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:264)
org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:107)
org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:72)
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:110)
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:217)
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:229)
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:148)
org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)


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_ order by this_.name asc

Session Factory:

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>Group.hbm.xml</value>
<value>User.hbm.xml</value>
<value>UserGroup.hbm.xml</value>
<value>GroupAdmin.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.connection.release_mode">on_close</prop>
</props>
</property>
</bean>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 26, 2006 4:33 pm 
Regular
Regular

Joined: Wed Nov 01, 2006 2:17 pm
Posts: 78
Hat niemand eine Idee?


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

Joined: Wed Nov 01, 2006 2:17 pm
Posts: 78
Es lag am Verwenden des Tabellennamens "Group", was gleichzeitig ein Schlüsselwort in SQL ist. Nach der Änderung hat es wieder funktioniert.


Top
 Profile  
 
 Post subject: GrammarException
PostPosted: Wed Nov 29, 2006 7:02 am 
Beginner
Beginner

Joined: Thu Nov 23, 2006 5:09 am
Posts: 21
Gilt meist auch für USER, es ist ein ist ein reserved Word, meist Parameter oder Function der DB. (zB Oracle)

Taucht es dann in Deinen Statements auf ist das Statement natürlich vom Format ungültig.


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.