-->
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: ERROR: syntax error at or near "group"
PostPosted: Mon Feb 13, 2006 11:52 am 
Newbie

Joined: Mon Feb 13, 2006 11:42 am
Posts: 2
We have a table named "group". I know, that group is keyword, but Hibernate should be able to handle this. When I copy generated SQL into some SQL browser and add " around group and specify real value for group.id, select works well.

Or is this supposed to be a bug of PG JDBC driver?

Hibernate version: 3.1.1

Mapping documents:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/billing</property>
<property name="hibernate.connection.username">billing</property>
<property name="hibernate.connection.password">billing</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>

<!-- Misc hibernate settings. -->
<property name="show_sql">true</property>
<property name="use_outer_join">true</property>
<property name="cglib.use_reflection_optimizer">false</property>
<property name="query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
<property name="transaction.flush_before_completion">true</property>
<property name="transaction.auto_close_session">true</property>

<!-- Project mapping files. -->
<mapping resource="sk/bgs/billing/worker/db/Group.hbm.xml" />
<!--<mapping resource="sk/bgs/billing/worker/db/Bill.hbm.xml" />-->
<mapping resource="sk/bgs/billing/worker/db/SubscriberLine.hbm.xml" />
</session-factory>
</hibernate-configuration>

Group.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>
<class name="sk.bgs.billing.worker.db.Group" table="groups">

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

<property name="customerId" type="long" column="customer_id" not-null="false"/>
<property name="slice" type="int" column="slice" not-null="false"/>
<property name="parentId" type="long" column="parent_id" not-null="false"/>
<property name="name" type="string" column="name" not-null="false"/>
<property name="createInfoBill" type="boolean" column="info_bill_flag" not-null="false"/>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
This part is enough in this case :-)
Group group = loadGroup(groupId);

Full stack trace of any exception that occurs:
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "group"
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1512)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1297)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:188)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:430)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:346)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:250)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1785)
... 15 more

Name and version of the database you are using:
PostgresQL 8.1

The generated SQL (show_sql=true):
Hibernate: select group0_.id as id0_0_, group0_.customer_id as customer2_0_0_, group0_.slice as slice0_0_, group0_.parent_id as parent4_0_0_, group0_.name as name0_0_, group0_.info_bill_flag as info6_0_0_ from group group0_ where group0_.id=?

Debug level Hibernate log excerpt:
13.02.2006 16:08:00 WARNING: SQL Error: 0, SQLState: 42601
13.02.2006 16:08:00 SEVERE: ERROR: syntax error at or near "group"
13.02.2006 16:08:00 INFO: Error performing load command


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 5:18 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
This isn't Hibernate's fault, or the driver's. It's a poor choice of table names.

The easiest workaround is to specify the table name in your mapping file with the schema.. use 'table="dbo.group"' or whatever. Then the SQL parser in the server (not Hibernate, not JDBC) won't parse "group" as a keyword.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 14, 2006 5:33 am 
Newbie

Joined: Mon Feb 13, 2006 11:42 am
Posts: 2
I agree with table name choice, but I can't make a decision on that (but maybe it will be changed because of this). Thanks for the tip - it works.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 14, 2006 4:33 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Then you should rate the post :)


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.