ric*_*ich 18 java postgresql orm hibernate
我正在通过Hibernate(注释)使用Postgres,但它似乎在处理User对象时失败了:
12:09:16,442 ERROR [SchemaExport] Unsuccessful: create table User (id bigserial not null, password varchar(255), username varchar(255), primary key (id))
12:09:16,442 ERROR [SchemaExport] ERROR: syntax error at or near "User"
Run Code Online (Sandbox Code Playgroud)
如果我手动运行SQL,我必须在表名周围加上引号,因为用户似乎是一个postgres关键字,但我怎么能说服hibernate自己做呢?
提前致谢.
Pas*_*ent 39
使用保留关键字时,您需要转义表名.在JPA 1.0中,没有标准化的方法,Hibernate特定的解决方案是使用反引号:
@Entity
@Table(name="`User`")
public class User {
...
}
Run Code Online (Sandbox Code Playgroud)
在JPA 2.0中,标准化语法如下所示:
@Entity
@Table(name="\"User\"")
public class User {
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7525 次 |
| 最近记录: |