映射实体,列表为地图值。通过JDBC语句执行DDL“如果存在`single_line`,则丢弃表”时出错

来源:爱站网时间:2021-09-16编辑:网友分享
我正在尝试创建一个将Csv文件保存到数据库的应用程序。编译时出现错误,并且数据未完全保存在MySql DB中。 CVS文件的每一行都是一个列表,它是一个...

问题描述


我正在尝试创建一个将Csv文件保存到数据库的应用程序。编译时出现错误,并且数据未完全保存在MySql DB中。

CVS文件的每一行都是一个列表,它是地图的一部分。我的实体的映射注释有问题吗?

这里是实体:

import javax.persistence.*;
import java.util.Map;

@Entity
@Table(name = "map_of_single_lists")
public class MapEntity {

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

@ManyToMany(targetEntity=pl.manciak.excelparser.LinesEntity.class)
@MapKeyClass(Long.class)
private Map mapa;

public MapEntity() {
}

public Long getId() {
    return id;
}

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

public Map getMapa() {
    return mapa;
}

public void setMapa(Map mapa) {
    this.mapa = mapa;
}

@Entity
@Table(name="single_line")
public class LinesEntity implements Serializable{

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

@ElementCollection
private List singleLine;


public LinesEntity() {
}

public Long getId() {
    return id;
}

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

public List getSingleLine() {
    return singleLine;
}

public void setSingleLine(List singleLine) {
    this.singleLine = singleLine;
}

application.properties

spring.jpa.properties.hibernate.hbm2ddl.auto=create
logging.level.org.hibernate.SQL= DEBUG

spring.datasource.url=jdbc:mysql://127.0.0.1:3306/newapp
spring.datasource.username=root
spring.datasource.password=1234
spring.h2.console.enabled=true

错误:

2020-02-25 14:40:35.187 DEBUG 6504 --- [           main] org.hibernate.SQL                        : alter table `map_of_single_lists_mapa` drop foreign key `FKqcxcam32e9xly5k8nqppj7t9u`
2020-02-25 14:40:35.203  WARN 6504 --- [           main] o.h.t.s.i.ExceptionHandlerLoggedImpl     : GenerationTarget encountered exception accepting command : Error executing DDL "alter table `map_of_single_lists_mapa` drop foreign key `FKqcxcam32e9xly5k8nqppj7t9u`" via JDBC Statement

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table `map_of_single_lists_mapa` drop foreign key `FKqcxcam32e9xly5k8nqppj7t9u`" via JDBC Statement


....


2020-02-25 14:40:35.204 DEBUG 6504 --- [           main] org.hibernate.SQL                        : alter table `map_of_single_lists_mapa` drop foreign key `FKmy4dokdghspd6asaa66i2r8lu`
2020-02-25 14:40:35.206  WARN 6504 --- [           main] o.h.t.s.i.ExceptionHandlerLoggedImpl     : GenerationTarget encountered exception accepting command : Error executing DDL "alter table `map_of_single_lists_mapa` drop foreign key `FKmy4dokdghspd6asaa66i2r8lu`" via JDBC Statement

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table `map_of_single_lists_mapa` drop foreign key `FKmy4dokdghspd6asaa66i2r8lu`" via JDBC Statement


....


2020-02-25 14:40:35.245 DEBUG 6504 --- [           main] org.hibernate.SQL                        : drop table if exists `single_line`
2020-02-25 14:40:35.248  WARN 6504 --- [           main] o.h.t.s.i.ExceptionHandlerLoggedImpl     : GenerationTarget encountered exception accepting command : Error executing DDL "drop table if exists `single_line`" via JDBC Statement

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "drop table if exists `single_line`" via JDBC Statement


....


2020-02-25 14:40:35.360 DEBUG 6504 --- [           main] org.hibernate.SQL                        : create table `single_line` (`id` bigint not null, primary key (`id`)) engine=InnoDB
2020-02-25 14:40:35.365  WARN 6504 --- [           main] o.h.t.s.i.ExceptionHandlerLoggedImpl     : GenerationTarget encountered exception accepting command : Error executing DDL "create table `single_line` (`id` bigint not null, primary key (`id`)) engine=InnoDB" via JDBC Statement

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table `single_line` (`id` bigint not null, primary key (`id`)) engine=InnoDB" via JDBC Statement


思路:


好吧,我将属性更改为uptadte,并且可以正常工作。spring.jpa.properties.hibernate.hbm2ddl.auto =更新

但是我仍然不确定映射是否正确。在数据库中,我有23行,在csv文件中,我有100行

上一篇:JavaFX:如何使选定的单元格更加可见

下一篇:将大型xml文件加载到Snowflake中并通过标签进行展平

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载