首页 > 解决方案 > java.sql.SQLSyntaxErrorException:“字段列表”中的未知列“column_name”-实体中的映射与数据库中的映射相同

问题描述

我收到了“accepted_at”列标题中的错误,但是我看不到我在哪里犯了错误,因为我检查了列的名称并且实体似乎已正确注释。使用了 Lombok 所以不要想知道为什么没有 setter 和 getter

@Id
@GeneratedValue
private Long id;
private Long version;

@Column(name = "accepted_at")
private Date acceptedAt;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "accepted_by_id")
private Account acceptedBy;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "account_id")
private Account account;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "token_id")
private Token token;

@Column(name = "date_created")
private Date dateCreated;

@Column(name = "is_accepted")
private Boolean isAccepted;

@Column(name = "is_enabled")
private Boolean isEnabled;

@Column(name = "last_updated")
private Date lastUpdated;

@Column(name = "organization_id")
private String organizationId;

@Column(name = "pending_status")
private int pendingStatus;

@Column(name = "pending_status_date")
private Date pendingStatusDate;

@Column(name = "profile_type")
private int profileType;

@Column(name = "valid_from")
private Date validFrom;

@Column(name = "valid_to")
private Date validTo;

这是我如何通过脚本为配置文件创建表。

create table profile
(
id                   bigint(20) not null auto_increment,
version              bigint(20) not null,
accepted_at          datetime,
accepted_by_id       bigint(20),
account_id           bigint(20) not null,
token_id             bigint(20),
date_created         datetime,
is_accepted          bit(1) not null,
is_enabled           bit(1) not null,
last_updated         datetime,
organization_id      national varchar(10) not null,
pending_status       int(11),
pending_status_date  datetime,
profile_type         int(11) not null,
valid_from           datetime,
valid_to             datetime,
primary key (id),
key organization_id (organization_id)
);

我正在使用 application.yml 而不是 application.properites。我希望这在某种程度上有用

 spring:
  datasource:
   url: jdbc:mysql://localhost/*****?serverTimezone=GMT
   username: root
   password: ******
  jpa:
   open-in-view: false
 flyway:
  enabled: true
 thymeleaf:
  suffix: .html
  cache: false

标签: javamysqlhibernatemapping

解决方案


请将您的 yml 属性替换为以下内容:

spring:
  datasource:
   url: jdbc:mysql://localhost/focus3?serverTimezone=GMT
   username: root
   password: 123456
  jpa:
   open-in-view: false
    hibernate:
    naming:
      physical-strategy : org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
 flyway:
  enabled: true
 thymeleaf:
  suffix: .html
  cache: false

因为,您的 yml 属性应该像下面一样使用您的字段名称,

spring:
  jpa:
    hibernate:
      naming:
        physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

推荐阅读