The project I'm working on (which uses Java, Spring, Hibernate) has recently been changed from Oracle to MySQL. There are several cases where some of the properties in the code are reserved words in MySQL, such as "release".
There are several solutions: 1) rename the properties in the code and subsequent getter / setter methods, as well as update the code that calls these methods; 2) annotate the property in the code using @Column (name = "` release` "). This says hibernate indicates the name when talking to the database.
I would rather stay away from the first approach in order to reduce the chance of breaking more things. The second approach is "good", except that it is specific to MySQL. In our dev. we use HSQL, which does not like backlinks around these column names.
I looked at the org.hibernate.mapping.Column class, and I see that it has getQuotedName methods that I can potentially override if I could subclass Column and tell Hibernate to use my own column class.
What is the best way to solve this problem based on the preferred approach a) not to have codebase refactoring (b / c change of property names, getter / setter methods, etc.) and b) wish that the application still works in HSQL and MySQL.
It would be wise to have a property in the properties file that you could switch to enable / disable the column naming fix. This reminds me, I tried using a custom naming strategy and overriding the "columnName" method to surround the column name in the opposite direction ... this does not work even in MySQL.
java spring mysql hibernate hsqldb
codecraig
source share