I have a MySQL DB table which I cannot modify but have to insert values into. It has a column called key
which I need to insert into.
Now, my .hbm.xml file has:
<property name="key"
type="string"
column="key" />
The insert query generated hence fails. On adding [key], the generated SQL now contained key
but this also failed. On checking in MYSql Workbench, I found that key
can work.
However, if I change this in the file mentioned above, it reverts to the "key" as when using [key]. Can someone guide me as to how I can add key
and bring about the required insert?
There is a hibernate configuration option for this. It needs Hibernate 3.5 which I'm not sure if you're using based on your use of hbm files.
In your hibernate config set
hibernate.globally_quoted_identifiers=true
List of environment config is here
来源:https://stackoverflow.com/questions/17204538/how-do-i-put-backticks-in-a-column-name-called-key-for-hibernate