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 que开发者_如何学JAVAstion 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?
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
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.
精彩评论