0

构建使用 Hibernate 和 PostgreSQL 的 Javalin 应用程序时出现此错误。所有其他表都在正常创建,但是这个给了我这个错误,我不知道为什么。我已经看到了这个错误,但是当使用“用户”作为表名时会发生这种情况,可能会出售是内部表的 postgre 保留名称。

2021-06-24T18:43:16.449969+00:00 app[web.1]: Jun 24, 2021 6:43:16 PM org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException
2021-06-24T18:43:16.449977+00:00 app[web.1]: WARN: GenerationTarget encountered exception accepting command : Error executing DDL "create table sale (id  serial not null, date date, user varchar(255), primary key (id))" via JDBC Statement
2021-06-24T18:43:16.449978+00:00 app[web.1]: org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table sale (id  serial not null, date date, user varchar(255), primary key (id))" via JDBC Statement

销售类休眠注释是这样的:

@Entity
public class Sale implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
    @Column()
    private String user;
    @OneToMany(mappedBy = "sale")
    private Set<SoldProduct> products = new HashSet<>();
    @Column()
    private LocalDate date;

    public Sale(){
        this.date = LocalDate.now();
    }

    public Sale(String user, Set<SoldProduct> products){
        this.user = user;
        this.products = products;
        this.date = LocalDate.now();
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public Set<SoldProduct> getProducts() {
        return products;
    }

    public void setProducts(Set<SoldProduct> products) {
        this.products = products;
    }

    public void addProduct(SoldProduct product){
        products.add(product);
    }

    public LocalDate getDate() {
        return date;
    }

    public void setDate(LocalDate date) {
        this.date = date;
    }
} 

我在 Heroku PostgreSQL 上使用 java 11、hibernate 5.5.3 和 PostgreSQL95Dialect

4

1 回答 1

1

user 列是 postgres 中的保留字。尝试将其更改为其他内容。

例子:

@Column(name = "account_user")
private String user;
于 2021-06-24T19:35:04.273 回答