-->
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.  [ 3 posts ] 
Author Message
 Post subject: Upper case table names in PostgreSQL
PostPosted: Tue Oct 26, 2004 6:13 pm 
Newbie

Joined: Tue Oct 26, 2004 10:55 am
Posts: 1
When a table has upper case name the generates sql needs to quote the table name, like select * from "MTD_USER", otherwise the server will try to find a lower case table...

I saw the generated sql (show_sql=true) and it isn't quoted. The mapping file has the correct name (upper).

I solved lowering my tables... but it's truly a bug :)


Hibernate version: 2.1.6 (9.8.2004)

Name and version of the database you are using: postgresql-server-7.4.2-1


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 26, 2004 11:13 pm 
Newbie

Joined: Mon Aug 30, 2004 1:37 am
Posts: 16
Mauromartini,

this is not a bug - in PostgreSQL you need to quote your identifiers in order to preserve the upper casing. You say that your mapping file does have the names in uppercase, but I imagine that they are missing the quotes. Hibernate accommodates this:
Quote:
You may force Hibernate to quote an identifier in the generated SQL by enclosing the table or column name in backticks in the mapping document.

http://www.hibernate.org/hib_docs/reference/en/html/mapping.html#mapping-quotedidentifiers

I did find that the backtick did not work for the schema or sequence names (if you are using uppercase names) - so I resorted to using the standard xml predefined entity for a quote (") for those cases:
Code:
<generator class="sequence">
   <param name="sequence">&quot;MYSCHEMA&quot;.&quot;MYSEQUENCE&quot;</param>   
</generator>


This all works well for me.

Grainne.


Top
 Profile  
 
 Post subject: Re: Upper case table names in PostgreSQL
PostPosted: Sun Aug 23, 2009 8:48 pm 
Newbie

Joined: Sun Aug 23, 2009 8:27 pm
Posts: 3
I have a very large PostgreSQL database that I will be using with JBoss Seam. The database uses mixed-case column names per naming convensions at Sun Microsystems and IBM. Until finding this post, I was very surprised by the potential need to have to change all column names in the PostgreSQL database to lowercase in order for hibernate and PostgreSQL to successfully interact. Per this post, the backtick marks (`) solved the problem.

However, I would strongly suggest that either modifying Hibernate to allow for interacting with uppercase (and mixed case) in PostgreSQL without the backtick marks) and/or making it very clear in appropriate sections of hibernate, seam and postgresql documentation that backticks are required for upper case and mixed cast column names.

The workaround solution to this issue was as follows:
In the entity I added an @Column(name="`mixedCaseColumnName`").
For example:

@Entity
@Name("cat")
@Table(name="cats")

public class Cat implements Serializable
{
private Integer id;
private String name;
private String distinguishingFeatures;

public Cat() {}

public Cat(Integer id, String name, String distinguishingFeatures)
{
this.id = id;
this.name = name;
this.distinguishingFeatures = distinguishingFeatures;
}

(The definition statements for the id and name variables)

@Column(name="`distinguishingFeatures`")
public String getDistinguishingFeatures()
{
return distinguishingFeatures;
}

public void setDistinguishingFeatures(String distinguishingFeatures)
{
this.distinguishingFeatures = distinguishingFeatures;
}

@Override
public String toString()
{
return "Cat(" + id + "," + name + "," + distinguishingFeatures + ")";
}


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