[hibernate-issues] [Hibernate-JIRA] Commented: (HBX-1000) Problem with PostgreSQL using uppercase letters in tables
Moritz Winter (JIRA)
noreply at atlassian.com
Tue Aug 10 09:19:40 EDT 2010
[ http://opensource.atlassian.com/projects/hibernate/browse/HBX-1000?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=38018#action_38018 ]
Moritz Winter commented on HBX-1000:
------------------------------------
Found a solution that works for us to reverse engineer PostgreSQL databases with upper- and mixed case column- and tablenames.
All I had to do was to implement my own MetaDataDialect:
{noformat:title=PostgreSQLMetaDialect.java|overflow-x:auto}
package com.example;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.cfg.reveng.dialect.JDBCMetaDataDialect;
import org.hibernate.cfg.reveng.dialect.MetaDataDialect;
/**
* A implementation of the {@link MetaDataDialect} for the PostgreSQL Database.
* This is basically a wrapper around {@link JDBCMetaDataDialect} to provide case sensitive
* access to postgresql databases.
*
* @see <a href="http://opensource.atlassian.com/projects/hibernate/browse/HBX-1000">HBX-1000</a>
*/
public class PostgreSQLMetaDialect extends JDBCMetaDataDialect {
private static final Log log = LogFactory.getLog(PostgreSQLMetaDialect.class);
/*
* (non-Javadoc)
* @see org.hibernate.cfg.reveng.dialect.AbstractMetaDataDialect#needQuote(java.lang.String)
*/
public boolean needQuote(String name) {
log.debug("needQuote(" + name +")");
if(null != name && 0 != name.compareTo(name.toUpperCase())) {
return true;
} else {
return super.needQuote(name);
}
}
}
{noformat}
And configure Hibernate to use the MetaDialect:
{noformat:title=hibernate.cfg.xml}
hibernatetool.metadatadialect=com.example.PostgreSQLMetaDialect
{noformat}
*Notes*:
* If youre using JBoss Seam Tools you can add the {{hibernatetool.metadatadialect}} to the file {{hibernate-console.properties}} which is generated with each new seam project.
* Don't forget to include the {{com.example.PostgreSQLMetaDialect}} in your Java Build Path (Properties->Java Build Path).
> Problem with PostgreSQL using uppercase letters in tables
> ---------------------------------------------------------
>
> Key: HBX-1000
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-1000
> Project: Hibernate Tools
> Issue Type: Bug
> Components: reverse-engineer
> Affects Versions: 3.2.beta11
> Environment: Hibernate 3.2.5.ga, Hibernate Tools 3.2.0 beta9a, PostgreSql 8.2, postgresql-8.2-506.jdbc3.jar, Eclipse 3.3.0, all running on Windows XP at the moment (including PostgreSql)
> Reporter: Ruediger Engelberger
>
> I have problems using Hibernate tools when using upper case letters in a PostgreSQL database.
> I can configure Hibernate Tools for my local PostgreSql installation without any problems. I can access the table structure in the view Hibernate Configurations and do reverse engineering by creating XML mappings and beans. No problem.
> But when I'm using upper case characters in table names Hibernate Tools can't access the table structures any more. Hibernate Configuration shows the tables, but when I want to see the columns, it doesn't show anything. Reverse engineering also doesn't work any more.
> So, the following works:
> TABLE cms_clusterMessage
> pk_clustermessageid
> fk_clusternodeid
> messagetype
> messagedetail
> The following doesn't work:
> TABLE cms_clusterMessage
> PK_ClusterMessageId
> FK_ClusterNodeId
> MessageType
> MessageDetail
> I tried to use different JDBC drivers because I thought it could be a bug of the driver. But it wasn't.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list