1

We came across the following situation.

Please note that I know reserved words should not be used for table names, but I'm asking the question anyway out of curiosity more than anything.

We are using Spring + Hibernate to manage our database. I am adding a new model to the database called Group. So, I define my model as:

@Entity
@Table(name = "group")
public class Group {
    ...
}

Now, the problem is, when recreating the tables, the SQL that gets generated looks as follows:

create table group (...)

This unfortunately is not allowed in MySQL since group is a reserved word. The correct SQL should be:

create table `group`(...)

Is there any way for me to do this?

Nico Huysamen
  • 10,217
  • 9
  • 62
  • 88

2 Answers2

2

You can force Hibernate to escape identifiers by doing this:

http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-quotedidentifiers

Basically, you can quote them yourself, and then Hibernate will use the appropriate quoting technique according to the dialect

octav
  • 1,181
  • 7
  • 6
0

You could try to implement your own org.hibernate.cfg.NamingStrategy, which add the backticks to all tables. -- But I am sure that this abuse the NamingStrategy class.

Ralph
  • 118,862
  • 56
  • 287
  • 383