使用ImprovedNamingStrategy创建表时出错

Jaa*_*nus 0 java postgresql spring hibernate spring-mvc

我的pojo看起来像这样:

@Entity
@Table(name = "USERS")
public class User {
Run Code Online (Sandbox Code Playgroud)

当我保留名称时,一切正常,hibernate sql log:

 create table users (id int8 not null, username varchar(255), primary key (id))
Run Code Online (Sandbox Code Playgroud)

当我删除注释时,我得到:

Hibernate: create table user (id int8 not null, username varchar(255), primary key (id))
19:24:43 [localhost-startStop-23] ERROR o.h.tool.hbm2ddl.SchemaExport - HHH000389: Unsuccessful: create table user (id int8 not null, username varchar(255), primary key (id))
19:24:43 [localhost-startStop-23] ERROR o.h.tool.hbm2ddl.SchemaExport - ERROR: syntax error at or near "user" Position: 14
Run Code Online (Sandbox Code Playgroud)

我试图使用它,因为它在我的xml中定义:

<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy" />
Run Code Online (Sandbox Code Playgroud)

任何建议,为什么命名策略不起作用?

axt*_*avt 6

默认表名USER是保留关键字.在这种情况下,您必须name明确指定,以便为其添加必要的转义:

@Entity
@Table(name = "`USER`")
public class User { ... }
Run Code Online (Sandbox Code Playgroud)