【问题标题】:JPA With postgresqlJPA 与 postgresql
【发布时间】:2018-09-10 10:39:05
【问题描述】:

当我使用 PostgreSQL 数据库在 Jpa 中创建表实体时,

tire - 

 @Entity
 @Immutable
  public class User_entity_t implements Serializable, Cloneable {

    private static final long serialVersionUID = -7049957706738879274L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id", updatable = false, nullable = false)
    private Long _judId;

@Column(nullable = false)
private String name;

我得到异常

{syntax error at or near "auto_increment"} Primary Key Id

【问题讨论】:

  • 听起来好像您的混淆层不知道 Postgres 如何处理“自动递增”列(serialidentity
  • 1) 您应该避免使用 AUTO 并选择 IDENTITY。 2) auto_increment 听起来像 MySQL 你有正确的方言集吗?
  • @SimonMartinelli 感谢您的回复。但是当我使用 Id GeneratedValue(strategy = GenerationType.IDENTITY) Column(columnDefinition = "serial") private Long id;同样的错误
  • 你确定你为 Postgres 设置了正确的语法吗?

标签: postgresql hibernate spring-data-jpa


【解决方案1】:

auto_increment 听起来像 MySQL

您必须设置正确的 Hibernate 方言。

【讨论】:

    猜你喜欢
    • 2017-03-22
    • 2015-01-19
    • 1970-01-01
    • 2018-03-17
    • 1970-01-01
    • 2023-03-08
    • 2011-01-05
    • 1970-01-01
    • 2013-01-29
    相关资源
    最近更新 更多