-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem with PostgreSQL case sensitive column names
PostPosted: Wed Oct 14, 2009 2:24 pm 
Newbie

Joined: Fri Apr 11, 2008 11:45 pm
Posts: 7
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 !


Top
 Profile  
 
 Post subject: Re: Problem with PostgreSQL case sensitive column names
PostPosted: Thu Oct 15, 2009 8:28 am 
Newbie

Joined: Fri Apr 11, 2008 11:45 pm
Posts: 7
Can anybody help me ?

I suspect Postgresql is the one lowercasing the actual SQL query ...

One solution would be to pass the table and column name between quotes.
Is it possible to do this in Hibernate ?

Thank you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.