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
|