Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
395 views
in Technique[技术] by (71.8m points)

java - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...