Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I put backticks in a column name called key for hibernate

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?

like image 673
gran_profaci Avatar asked Jun 20 '13 02:06

gran_profaci


1 Answers

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

like image 132
Lionel Port Avatar answered Oct 16 '22 16:10

Lionel Port