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:
- Create a subclass of JDBCMetaDataDialect.
- Configure Hibernate to use the PostgreSQLMetaDialect by updating hibernate.cfg.xml.
- 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
No comments:
Post a Comment