Make hibernate backquote all table / column names

I came across an outdated system written to work with MySQL 5.0, and now I need to port it to MysQL 5.5 (requirement). I found that one column was named maxvalue , which seems to be the system word in MySQL 5.5. Thus, all my Hibernate queries that include this column give a syntax error:

Reason: java.sql.BatchUpdateException: you have an error in your SQL syntax; check the manual that matches your version of MySQL server for the correct syntax to use near 'maxvalue

Hibernate doesn't seem to do it automatically, but rather quotes `around the field name. If I retrieve the query, in `maxvalue` it works correctly in MySQL 5.5.

I found a solution on how to explicitly use backquotes for a specific field / table. The thing is, I'm not sure how many other column names will create such a problem. Is there a way to force Hibernate to automatically quote all table / column names? (which will produce valid SQL, and I do not know why it does not do this by default for MySQL).

EDIT : This discussion almost makes me believe that what I want is impossible.

+13
java mysql escaping hibernate
Feb 18 '13 at 8:29
source share
2 answers

There is an undocumented property for this purpose. Using,

 <property name="hibernate.globally_quoted_identifiers" value="true"/> 

or

 <property name="hibernate.globally_quoted_identifiers">true</property> 
+35
Feb 18 '13 at 19:15
source share

Does this property behave differently in Oracle and MySQL? In my tests, it adds double quotes to identifiers in Oracle and adds back quotes in MySQL, is that correct? Does anyone else know the official answers?

0
Jul 09 '19 at 3:32
source share



All Articles