Я пишу простое Java-приложение "Hello world", использующее MySQL в Linux.
Я пытаюсь автоматически настроить схему, вызывая скрипт из файла persist.xml.
Я получаю эту ошибку, когда пытаюсь создать экземпляр своей JPA EntityManagerFactory:
WARN: GenerationTarget encountered exception accepting command : Error executing DDL "CREATE TABLE task (" via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "CREATE TABLE task (" via JDBC Statement
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlString(SchemaCreatorImpl.java:440)
...
Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:782)
at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:666)
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)
... 15 more
Я прочитал другие ссылки, я попытался явно установить «MySQL57Dialect» (он автоматически определял «MySQL57Dialect» даже до того, как я добавил это свойство), я попытался упростить сценарий SQL и т. Д. И т. Д. - все безрезультатно.
ИНФОРМАЦИЯ О ВЕРСИИ:
Ubuntu 18.04.1 LTS
mysql Ver 14.14 Distrib 5.7.24, for Linux (x86_64) using EditLine wrapper
OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4)
SQL Script (текущая, урезанная версия: работает нормально из mysql CLI):
CREATE TABLE task (
id BIGINT NOT NULL auto_increment,
summary VARCHAR(20) NOT NULL,
priority VARCHAR(10) NOT NULL DEFAULT 'NORMAL',
status VARCHAR(10) NOT NULL DEFAULT 'PENDING',
created_on TIMESTAMP DEFAULT current_timestamp,
PRIMARY KEY(id)
);
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="com.example.hellohibernate.jpa" transaction-type="RESOURCE_LOCAL">
<class>com.example.hellohibernate.Task</class>
<class>com.example.hellohibernate.TaskUpdate</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL57Dialect" />
<!-- Configuring The Database Connection Details -->
<property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/test2" />
<property name="javax.persistence.jdbc.user" value="test" />
<property name="javax.persistence.jdbc.password" value="test123" />
<!-- First time only, create from schema: -->
<property name="javax.persistence.schema-generation.database.action" value="create" />
<property name="javax.persistence.schema-generation.create-source" value="script"/>
<property name="javax.persistence.schema-generation.create-script-source" value="META-INF/mkdb.mysql.sql" />
</properties>
</persistence-unit>
</persistence>
Журнал консоли:
Jan 12, 2019 11:59:54 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000412: Hibernate Core {5.4.0.Final}
...
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL57Dialect
...
WARN: GenerationTarget encountered exception accepting command : Error executing DDL "create table task (" via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table task (" via JDBC Statement
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
...
Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:782)
at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:666)
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)
... 15 more
Есть предложения?