I would like to create an object in MS SQL with hibernate, name of this table is "user". it does not work!. I think this problem may caused by name of table/entity, user is keyword. what should I do to have table with name "user"?
@Entity
@Table(name = "user")
public class User {
Enclose the table name in square braces:
@Entity
@Table(name = "[user]")
public class User {
That way Hibernate will escape it when it creates the table. If you put all your field and table names in square braces as a rule, you never have to consider the underlying DBMS when setting up your mappings.
<rant>It always bothered me that you had to do this. One of the major goals of Hibernate is to isolate your code from the underlying database -- I never understood why the dialect implementations don't properly handle escaping reserved keywords.</rant>
See also: Using database reserved keywords in Hibernate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With