我的pojo看起来像这样:
@Entity
@Table(name = "USERS")
public class User {
当我保留名称时,一切正常,hibernate sql log:
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" />
任何建议,为什么命名策略不起作用?
答案 0 :(得分:6)
默认表名USER
是保留关键字。在这种情况下,您必须明确指定name
才能添加必要的转义:
@Entity
@Table(name = "`USER`")
public class User { ... }
答案 1 :(得分:1)
PostgreSQL关键字列表:
http://www.postgresql.org/docs/9.1/static/sql-keywords-appendix.html
标记为“保留”是那些不允许作为列或标记的标记 表名。
你的桌名:
USER reserved
实际上是保留的。
因此,您无法在PostgreSQL中创建名为user
的表。这就是为什么注释一切正常,因为注释指定了名称users
。没有这样的关键字。