Bjo*_*che 14 java postgresql hibernate jpa
我正在使用Hibernate,并且有一个名为"User"的持久化类.由于这是一个关键字,我用不同的名称标记了@Entity属性(我已经看过,例如,这个问题: 在postgresql hibernate中无法使用名为"user"的表)
但是,我仍然遇到麻烦,因为这个类扩展了另一个,看起来hibernate仍然试图使用"user"作为列名并搞砸了:
@Entity( name = "XonamiUser" )
public class User extends PropertyContainer {
...
Run Code Online (Sandbox Code Playgroud)
和
@MappedSuperclass
public abstract class PropertyContainer implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected long key;
/** tags */
@ElementCollection
protected Set<String> tags;
@ElementCollection
protected Set<String> searchList;
...
Run Code Online (Sandbox Code Playgroud)
我扩展PropertyContainer的其他类似乎工作正常.
这是hibernate中的一个错误吗?有没有办法解决这个重构的问题?谢谢!
以下是我看到的错误(略微清理):
WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 42601
ERROR org.hibernate.util.JDBCExceptionReporter - Batch entry 0 insert into user_search_list (user, search_list) values ('1', 'bjorn') was aborted. Call getNextException to see the cause.
WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 42601
ERROR org.hibernate.util.JDBCExceptionReporter - ERROR: syntax error at or near "user"
Position: 31
Run Code Online (Sandbox Code Playgroud)
fil*_*rem 44
user是PostgreSQL中的保留关键字.仅允许作为带引号的标识符.
你必须强制Hibernate "user"在这个INSERT命令中使用引用.
我不是Hibernate专家但也许这个Hibernate将用户模型保存到Postgres会有帮助吗?
我有点困惑你指的是名为 User 的列或表...你可以使用@Table -annotation 为 JPA 中的实体设置表名:
@Entity
@Table(name = "XonamiUser")
public class User extends PropertyContainer {
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23764 次 |
| 最近记录: |