Hi !
Hibernate V 3.3.2 GA
DB : PostgreSQL 8.3
I have some trouble with my mappings and the column names in my postgresql database.
In my database an example table is defined as follow :
Code:
CREATE TABLE "public"."poitype"(
"id" int8 NOT NULL DEFAULT nextval('poitype_id_seq'::regclass),
"Name" varchar(255) NOT NULL ,
"Description" varchar(255) ,
PRIMARY KEY ("id")
) WITHOUT OIDS;
The corresponding mapping file is as follow:
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="model.POIType" table="poitype" catalog="public">
<id name="id" type="java.lang.Long">
<column name="id" />
<generator class="sequence">
<param name="sequence">poitype_id_seq</param>
</generator>
</id>
<property name="name" type="java.lang.String" not-null="true" column="Name" />
<property name="description" type="java.lang.String" column="Description" />
</class>
</hibernate-mapping>
With the simple HQL statement
"from POIType"
the corresponding query in the console is
"Hibernate: select poitype0_.id as id93_, poitype0_.Name as Name93_, poitype0_.Description as Descript3_93_ from public.poitype poitype0_"
which seems to keep the column names with the correct case.
However I get the folloing exception :
Code:
Caused by: org.postgresql.util.PSQLException: ERREUR:[color=#FF0000] la colonne poitype0_.name n'existe pas[/color]
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1592)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1327)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:192)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:350)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:254)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1812)
at org.hibernate.loader.Loader.doQuery(Loader.java:697)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2232)
... 60 more
The part in red suggests that the case of the column name has been changed to lowercase "poitype0_.name" which should be "poitype0_.Name" for the database to understand the query correctly.
I tried lowercasing the column name in the database and this works correctly. However this is not an option for me as it would mean renaming the fields on more than 300 tables ...
Is it possible to turn off the automatic lowercasing of the column name when the query is sent to the DB ...
What solutions do I have (besides renaming all the fields of my DB) ?
Thank you for your answer !