gran_profaci
gran_profaci

Reputation: 8461

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?

Upvotes: 5

Views: 1675

Answers (1)

Lionel Port
Lionel Port

Reputation: 3542

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

Upvotes: 6

Related Questions