Showing posts with label Hibernate Tool. Show all posts
Showing posts with label Hibernate Tool. Show all posts

Monday, January 26, 2015

Hibernate Mapping File PostgreSQL Uppercase letters | Hibernate Tool - Generate Mapping Files for PostgreSQL Tables with Uppercase Letters

Upper Case Letters Issue for Hibernate Mapping File Generation

I have problems using Hibernate tools when using uppercase letters in a PostgreSQL database (either in table name or column name).

Hibernate Configuration shows the tables, but it doesn't show columns. Reverse engineering also doesn't work.

The solution to this is to implement your own MetaDataDialect and put it into hibernate.cfg.xml.

Steps:

  1. Create a subclass of JDBCMetaDataDialect.
  2. Configure Hibernate to use the PostgreSQLMetaDialect by updating hibernate.cfg.xml.
  3. Add the class to the classpath.


Create Subclass of JDBCMetaDataDialect

The subclass of JDBCMetaDataDialect:

import org.hibernate.cfg.reveng.dialet.JDBCMetaDataDialect ;

public class PostgreSQLMetaDialect extends JDBCMetaDataDialect
{
    public boolean needQuote(String name)
    {        
        if(null != name && 0 != name.compareTo(name.toLowerCase()))
        {
            return true;
        } 
        else 
        {
            return super.needQuote(name);
        }
    }
}

Change hibernate.cfg.xml

hibernate.cfg.xml:

hibernatetool.metadatadialect=somepackage.PostgreSQLMetaDialect 





Create a Successful Online Store at Bigcommerce! Try it Free Now!