Make hibernate backquote all table / column names
I am faced with legacy system written to work with MySQL 5.0 and now need to migrate it to MysQL 5.5 (requirement). I found that one column was named maxvalue
, which seems to be system word in MySQL 5.5. Thus all my Hibernate queries that include this column give syntax error:
Caused by: java.sql.BatchUpdateException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'maxvalue
It seems that Hibernate does not automatically but backquotes ` around the field name. If I extract the query, backquote `maxvalue`
it runs correctly in MySQL 5.5.
I have found solution how to explicitly force backquotes for specific field / table. The thing is that I am not sure how many other column names will produce such problem. Is there a way to tell Hibernate to automatically backquote all table/ column names? (which will produce valid SQL and I don't know why it does not do that by default for MySQL).
EDIT: This discussion almost makes me believe that what I want is not possible.
Solution 1:
There is a non-documented property for this purpose. Use,
<property name="hibernate.globally_quoted_identifiers" value="true"/>
or
<property name="hibernate.globally_quoted_identifiers">true</property>