1

Using Hibernate and MySQL, I have this table named Order and a respective Order bean.

@Entity                                      
@org.hibernate.annotations.SelectBeforeUpdate(true)                   
@org.hibernate.annotations.DynamicUpdate(true)                        
@Table(name = "order")
public class Order {                         
   ... 
}

I get this error. I believe the reason is that order is
a reserved word in SQL, so the table name has to be qualified.

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 'order order4...

What is the way to solve this in a RDBMS-independent way?
I mean I don't want to simply qualify my table name with

@Table(name = "`order`")

if possible (because the backtick symbol is a MySQL-dependent qualifier).

What is the best way to solve this issue?

peter.petrov
  • 38,363
  • 16
  • 94
  • 159
  • It is always a good pratice not to use reserved words as tables, fields and what so ever on your model. I would go just for changing the table name, something like `orders` – Jorge Campos Feb 02 '15 at 23:18
  • @JorgeCampos I know this good practice. Thanks but that doesn't help me. I cannot change the table name. I am looking for a real solution here in terms of hibernate configuration. – peter.petrov Feb 02 '15 at 23:22
  • So you may looking for this: http://stackoverflow.com/a/17204648/460557 or this: http://stackoverflow.com/a/3463189/460557 or even this one: http://stackoverflow.com/a/3368289/460557 – Jorge Campos Feb 02 '15 at 23:28
  • 1
    @JorgeCampos Great, thanks, this works. I used the standard escaping `@Table(name = "\"order\"")`. This is translated perfectly by Hibernate to the backtick escaping (in the generated SQL code). Problem solved. – peter.petrov Feb 02 '15 at 23:32
  • That is great I will mark this question as a duplicate then. – Jorge Campos Feb 02 '15 at 23:33

0 Answers0