【问题标题】:Hibernate didn't create one of tablesHibernate 没有创建表之一
【发布时间】:2019-06-28 16:08:39
【问题描述】:

我正在学习 spring...,我构建了一个简单的应用程序。 我有一个问题,因为休眠不想生成模型之一.. 不知道怎么回事

import com.fasterxml.jackson.annotation.JsonIgnore;
import javax.persistence.*;
import java.io.Serializable;

@Entity
@Table(name="access_card")
public class AccessCard implements Serializable{

    private static final long serialVersionUID = -4015209774835055079L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="id")
    private Long id;

    @Column(name="key")
    private String key;
    @Column(name="enabled")
    private Boolean enabled;

    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", nullable = false)
    @JsonIgnore
    private User user;

    public Long getId() {
        return id;
    }

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

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public Boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public User getUser() {
        return user;
    }

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

其他类的编写方式类似,一切正常。 错误:

org.hibernate.tool.schema.spi.CommandAcceptanceException: 错误 执行 DDL “创建表 access_card(id bigint 不为空,已启用 位,键 varchar(255),user_id bigint 不为空,主键 (id)) engine=MyISAM" 通过 JDBC 语句

和属性

spring.jpa.hibernate.ddl-auto = update
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

【问题讨论】:

  • 生成除此之外的所有表
  • 我更改了“key”列的名称,它可以工作

标签: spring hibernate spring-boot


【解决方案1】:

关注您的评论,这里指出的问题

key varchar(255)

表名是保留关键字。

https://hibernate.atlassian.net/browse/HHH-4453

如果你还想要,解决方法是https://vladmihalcea.com/escape-sql-reserved-keywords-jpa-hibernate/

【讨论】:

    猜你喜欢
    • 2016-10-25
    • 2022-01-21
    • 2021-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-05
    • 1970-01-01
    相关资源
    最近更新 更多