I am trying to insert data when starting my application but it fails continuously and this exception is thrown, I don’t know what I am doing wrong, I have changed the Mysql dialect for version 8 it keeps failing.I have read similar post but it don’t work
here is the spring/hibernate when i start my app
Hibernate: alter table empleados drop foreign key if exists FK1dvvcamb3oxb2d9xqd9taug0u
Hibernate: alter table ventas drop foreign key if exists FK4dgjhccl2uuo8swmxlxb4ipb5
Hibernate: alter table ventas drop foreign key if exists FK8x8hnvfgwvw2cd7ii217kkuue
Hibernate: alter table ventas drop foreign key if exists FKm2vj8hr3u07dh7lf45hq7tman
Hibernate: drop table if exists clientes
Hibernate: drop table if exists departamentos
Hibernate: drop table if exists empleados
Hibernate: drop table if exists productos
Hibernate: drop table if exists users
Hibernate: drop table if exists ventas
Hibernate: create table clientes (id bigint not null auto_increment, apellido varchar(255), correo_electronico varchar(255), direccion varchar(255), fecha_registro datetime(6), nombre varchar(255), telefono varchar(255), primary key (id)) engine=InnoDB
Hibernate: create table departamentos (id bigint not null auto_increment, descripcion varchar(255), nombre varchar(255), primary key (id)) engine=InnoDB
Hibernate: create table empleados (id bigint not null auto_increment, apellido varchar(255), correo_electronico varchar(255), direccion varchar(255), fecha_contratacion datetime(6), fecha_nacimiento datetime(6), nombre varchar(255), salario double precision, telefono varchar(255), departamento_id bigint, primary key (id)) engine=InnoDB
Hibernate: create table productos (id bigint not null auto_increment, descripcion varchar(255), fecha_lanzamiento datetime(6), nombre varchar(255), precio double precision, stock integer, primary key (id)) engine=InnoDB
Hibernate: create table users (id integer not null auto_increment, created_at datetime(6), email varchar(255), enabled bit, locked bit, password varchar(255), rol varchar(255), updated_at datetime(6), username varchar(255), primary key (id)) engine=InnoDB
Hibernate: create table ventas (id bigint not null auto_increment, cantidad integer, fecha datetime(6), cliente_id bigint, empleado_id bigint, producto_id bigint, primary key (id)) engine=InnoDB
Hibernate: alter table empleados add constraint FK1dvvcamb3oxb2d9xqd9taug0u foreign key (departamento_id) references departamentos (id)
Hibernate: alter table ventas add constraint FK4dgjhccl2uuo8swmxlxb4ipb5 foreign key (cliente_id) references clientes (id)
Hibernate: alter table ventas add constraint FK8x8hnvfgwvw2cd7ii217kkuue foreign key (empleado_id) references empleados (id)
Hibernate: alter table ventas add constraint FKm2vj8hr3u07dh7lf45hq7tman foreign key (producto_id) references productos (id)
2023-01-16 17:07:39.254 INFO 10496 --- [ restartedMain] o.h.t.schema.internal.SchemaCreatorImpl : HHH000476: Executing import script 'file:/D:/eclipse%20workspace/company/target/classes/import.sql'
Hibernate: INSERT INTO departamentos (nombre, descripcion)
2023-01-16 17:07:39.262 WARN 10496 --- [ restartedMain] o.h.t.s.i.ExceptionHandlerLoggedImpl : GenerationTarget encountered exception accepting command : Error executing DDL "INSERT INTO departamentos (nombre, descripcion)" via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "INSERT INTO departamentos (nombre, descripcion)" via JDBC Statement
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlString(SchemaCreatorImpl.java:458) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applyImportSources(SchemaCreatorImpl.java:514) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.performCreation(SchemaCreatorImpl.java:183) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:138) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:124) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:168) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:85) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:335) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:471) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1498) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) ~[spring-orm-5.3.22.jar:5.3.22]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.3.22.jar:5.3.22]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409) ~[spring-orm-5.3.22.jar:5.3.22]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) ~[spring-orm-5.3.22.jar:5.3.22]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) ~[spring-context-5.3.22.jar:5.3.22]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) ~[spring-context-5.3.22.jar:5.3.22]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.22.jar:5.3.22]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.3.jar:2.7.3]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) ~[spring-boot-2.7.3.jar:2.7.3]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[spring-boot-2.7.3.jar:2.7.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[spring-boot-2.7.3.jar:2.7.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.3.jar:2.7.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.3.jar:2.7.3]
at com.company.project.CompanyApplication.main(CompanyApplication.java:10) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.7.3.jar:2.7.3]
Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.30.jar:8.0.30]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.30.jar:8.0.30]
at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:763) ~[mysql-connector-java-8.0.30.jar:8.0.30]
at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:648) ~[mysql-connector-java-8.0.30.jar:8.0.30]
at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:94) ~[HikariCP-4.0.3.jar:na]
at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java) ~[HikariCP-4.0.3.jar:na]
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
... 38 common frames omitted
properties
spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/empresa
spring.datasource.username=root
# spring.datasource.password=Mysql@123
# JPA-Hibernate
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MariaDB103Dialect
spring.jpa.properties.hibernate.dialect.storage_engine=innodb
spring.sql.init.mode=always
spring.jackson.default-property-inclusion = NON_NULL
mysql ,only these three queries
INSERT INTO departamentos (nombre, descripcion)
VALUES ('ventas', 'Departamento encargado de las ventas');
INSERT INTO departamentos (nombre, descripcion)
VALUES ('Marketing', 'Departamento encargado del marketing');
INSERT INTO departamentos (nombre, descripcion)
VALUES ('Recursos Humanos', 'Departamento encargado de los recursos humanos');
2
Answers
it works for me , idk why.
Set the configuration property:
By default, Hibernate uses
SingleLineSqlScriptExtractor
.