java - 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
解决方案
请将您的 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
推荐阅读
- flutter - 如何在 ListTileTheme 中使用形状?
- java - 添加“cors disable”时,安全配置对所有匹配器应用身份验证
- c# - EF6:参数“nameOrConnectionString”不能为空、空或仅包含空格
- r - 查找整个数据帧的分位数
- javascript - A* 寻路,路径未显示
- java - kafka流:同一主题中的不同对象
- asp.net - 我们如何使用 YAML 从构建中排除项目?
- angular - 如何在 @angular/cli 库中包含 mqtt.js
- java - 如果我使用 try-with-resources,如何不因事务而关闭连接?
- swift - 回调初始化程序(键盘工具栏)上的操作