qq_42200967 2021-10-17 18:14 采纳率: 0%
浏览 13

Spring JPA + H2,脚本初始化数据库生成了额外的重复字段

我的表初始化结构和初始化数据是通过类路径的脚本生成导入的。如下图:

img


schema.sql 是表结构,data.sql 是数据。

这是表结构 schema.sql:

create table if not exists Ingredient(
    id varchar(4) not null primary key, 
    name varchar(50) not null, 
    type varchar(10) not null
);
create table if not exists Taco(
    id identity, 
    name varchar(50) not null, 
    createAt timestamp not null
);
create table if not exists Taco_Ingredients(
    taco bigint not null, 
    ingredient varchar(4) not null
);
alter table Taco_Ingredients add foreign key(taco) references Taco(id);
alter table Taco_Ingredients add foreign key(ingredient) references Ingredient(id);
create table if not exists Taco_Order(
    id identity, 
    deliveryName varchar(50) not null, 
    deliveryStreet varchar(50) not null, 
    deliveryCity varchar(50) not null, 
    deliveryState varchar(2) not null, 
    deliveryZip varchar(10) not null, 
    ccNumber varchar(16) not null, 
    ccExpiration varchar(5) not null, 
    ccCVV varchar(3) not null, 
    placeAt timestamp not null
);
create table if not exists Taco_Order_Tacos(
    tacoOrder bigint not null, 
    taco bigint not null
);
alter table Taco_Order_Tacos add foreign key(tacoOrder) references Taco_Order(id);
alter table Taco_Order_Tacos add foreign key(taco) references Taco(id);

create table if not exists User(
    id identity,
    username varchar(20), 
    password varchar(20), 
    fullname varchar(20), 
    street varchar(20), 
    city varchar(20), 
    state varchar(20), 
    zip varchar(20), 
    phoneNumber varchar(20)
);

这是数据 data.sql:

delete from Taco_Order_Tacos;
delete from Taco_Ingredients;
delete from Taco;
delete from Taco_Order;
delete from Ingredient;
delete from User;
insert into Ingredient (id, name, type) values('FALO', 'Flour Tortilla', 'WRAP');
insert into Ingredient (id, name, type) values('COTO', 'Corn Tortilla', 'WRAP');
insert into Ingredient (id, name, type) values('GRBF', 'Ground Beef', 'PROTEIN');
insert into Ingredient (id, name, type) values('CARN', 'Carnitas', 'PROTEIN');
insert into Ingredient (id, name, type) values('TMTO', 'Diced Tomatoes', 'VEGGIES');
insert into Ingredient (id, name, type) values('LETC', 'Lettuce', 'VEGGIES');
insert into Ingredient (id, name, type) values('CHED', 'Cheddar', 'CHEESE');
insert into Ingredient (id, name, type) values('JACK', 'Monterry Jack', 'CHEESE');
insert into Ingredient (id, name, type) values('SLSA', 'Salsa', 'SAUCE');
insert into Ingredient (id, name, type) values('SRCR', 'Sour Cream', 'SAUCE');
insert into User(username, password, fullname, street, city, state, zip, phoneNumber) values('buzz', 'infinity', 'a', 'a', 'a', 'a', 'a', 'a');
insert into User(username, password, fullname, street, city, state, zip, phoneNumber) values('woody', 'bullseye', 'b', 'b', 'b', 'b', 'b', 'b');

这是我的项目配置信息 application.properties:

spring.sql.init.schema-locations=classpath:schema.sql
spring.sql.init.data-locations=classpath:data.sql

spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=sa
spring.datasource.password=

spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update

我遇到的问题是如下图,凡是脚本里是驼峰命名的,JPA 都给额外生成一个帕斯卡命名的字段。导致查询操作报错,我的 Spring Security 认证失败。

img

目前并没有什么线索可以排查,唯一知道的是,spring.jpa.hibernate.ddl-auto 取值 update 时,初始化的表结构才有数据,其他都没有数据。

  • 写回答

2条回答 默认 最新

  • 心怀啊 2021-10-17 23:43
    关注
    评论

报告相同问题?

问题事件

  • 创建了问题 10月17日

悬赏问题

  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿