我的 pojo 看起来像这样:
@Entity
@Table(name = "USERS")
public class User {
当我将名称保留在那里时,一切正常, hibernate sql 日志:
create table users (id int8 not null, username varchar(255), primary key (id))
当我删除注释时,我得到:
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
我正在尝试使用它,因为它在我的 xml 中定义:
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy" />
有什么建议吗,为什么命名策略不起作用?
最佳答案
默认表名 USER
是保留关键字。在这种情况下,您必须明确指定 name
以便为其添加必要的转义:
@Entity
@Table(name = "`USER`")
public class User { ... }
关于java - 使用 ImprovedNamingStrategy 创建表时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13688645/