Я пытаюсь создать приложение, которое будет сохранять файл 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<Long, LinesEntity> mapa;
public MapEntity() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Map<Long, LinesEntity> getMapa() {
return mapa;
}
public void setMapa(Map<Long, LinesEntity> 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<String> singleLine;
public LinesEntity() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public List<String> getSingleLine() {
return singleLine;
}
public void setSingleLine(List<String> 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