Sunday, July 28, 2013

Filled Under: , , , , ,

How to map Postgres capital names to Hibernate

English Hibernate Java PostgreSQL Simulation Model System Troubleshooting
When I was developing the Simulation Model System (SimModSys), I faced this issue.

I'm from the school that believes that the database should be developed first and independently from the system, to serve the purpose of maintaining the data integrity, and the application should integrate to the existing database to apply logic on the data, but not to force how the data should be represented. So I designed the database first ignoring that there were issues between Hibernate and Postgres capital letters.

Instead of changing the database I decided to fight for it, after all it was a learning personal project. 

I received a partial answer that I completed later at StackOverflow. In short, what you have to do is the following:

  • Escape every table that has capital letters (using \"):
  • Escape every field that has capital letters (using \"):
  • Escape joins that include columns that have capital letters (strangely, using `):

It is a tedious work. This worked for me with PostgreSQL 9.1.9, Hibernate 4.1.3 and Java 7. 

For a complete example you can review the code at BitBucket of any of the classes of the SimModSys project's persistence package.



I'm a software developer, with main interest in SOA, Web and Mobile applications design and development. I'm also interested in Travel, Politics, Photography and Volunteering.

"We are what we repeatedly do.Excellence, then, is not an act, but a habit." (Aristotle) is my motto .


Copyright © Librethinking.
Designed by Templateism. Hosted on Blogger Platform.