9
respostas

Error executing DDL "create table order

Na hora de subir o servidor, não foi possível criar a tabela e aconteceu essa exceção:

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table order (id bigint not null auto_increment, type varchar(255), value decimal(19,2), primary key (id)) engine=InnoDB" via JDBC Statement
    at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlString(AbstractSchemaMigrator.java:559) [hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlStrings(AbstractSchemaMigrator.java:504) [hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.createTable(AbstractSchemaMigrator.java:277) [hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.internal.GroupedSchemaMigratorImpl.performTablesMigration(GroupedSchemaMigratorImpl.java:71) [hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.performMigration(AbstractSchemaMigrator.java:207) [hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.doMigration(AbstractSchemaMigrator.java:114) [hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:184) [hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:73) [hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:316) [hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:469) [hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1259) [hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) [spring-orm-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) [spring-orm-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:391) [spring-orm-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at java.util.concurrent.FutureTask.run(Unknown Source) ~[na:1.8.0_241]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) ~[na:1.8.0_241]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) ~[na:1.8.0_241]
    at java.lang.Thread.run(Unknown Source) ~[na:1.8.0_241]
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 'order (id bigint not null auto_increment, type varchar(255), value decimal(19...' at line 1
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.21.jar:8.0.21]
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.21.jar:8.0.21]
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.21.jar:8.0.21]
    at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:764) ~[mysql-connector-java-8.0.21.jar:8.0.21]
    at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:648) ~[mysql-connector-java-8.0.21.jar:8.0.21]
    at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95) ~[HikariCP-3.4.5.jar:na]
    at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java) ~[HikariCP-3.4.5.jar:na]
    at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    ... 18 common frames omitted
9 respostas

Continuação:

2020-09-26 11:49:36.837  INFO 1084 --- [         task-1] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-09-26 11:49:36.845  INFO 1084 --- [         task-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
Exception in thread "task-2" java.lang.IllegalStateException: EntityManagerFactory is closed
    at org.hibernate.internal.SessionFactoryImpl.validateNotClosed(SessionFactoryImpl.java:509)
    at org.hibernate.internal.SessionFactoryImpl.getProperties(SessionFactoryImpl.java:503)
    at org.springframework.boot.autoconfigure.orm.jpa.DataSourceInitializedPublisher.findDataSource(DataSourceInitializedPublisher.java:105)
    at org.springframework.boot.autoconfigure.orm.jpa.DataSourceInitializedPublisher.publishEventIfRequired(DataSourceInitializedPublisher.java:97)
    at org.springframework.boot.autoconfigure.orm.jpa.DataSourceInitializedPublisher.access$100(DataSourceInitializedPublisher.java:50)
    at org.springframework.boot.autoconfigure.orm.jpa.DataSourceInitializedPublisher$DataSourceSchemaCreatedPublisher.lambda$postProcessEntityManagerFactory$0(DataSourceInitializedPublisher.java:200)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
2020-09-26 11:49:36.847  INFO 1084 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2020-09-26 11:49:36.849  INFO 1084 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2020-09-26 11:49:36.857  INFO 1084 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
2020-09-26 11:49:36.859  INFO 1084 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-09-26 11:49:36.868  INFO 1084 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-09-26 11:49:36.870 ERROR 1084 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Web server failed to start. Port 8080 was already in use.

Action:

Identify and stop the process that's listening on port 8080 or configure this application to listen on another port.

Na hora de criar o "root" no Heidi, no campo "Tipo de rede" aparece "MySQL (TCP/IP)", mas não aparece a opção "MariaDB or MySQL (TCP/IP)", como no programa do professor.

Contudo, embaixo de "Tipo de rede" aparece o campo "Library", que não aparece para o professor. Nesse campo, existem as opções "libmariadb.dll", "libmysql-6.1.dll" e "libmysql.dll". Não sei se tem a ver com o erro que está acontecendo comigo.

Alguém poderia me ajudar?

Obrigado.

Henrique tem algumas coisas ai:

Esse erro ocorre quando já tem outra aplicação ou instancia ocupando a porta 8080

Web server failed to start. Port 8080 was already in use.

O erro de criação da tabela é um erro no sql.

create table order (id bigint not null auto_increment, type varchar(255), value decimal(19,2), primary key (id)) engine=InnoDB

'order (id bigint not null auto_increment, type varchar(255), value decimal(19...

ele esta colocando order como palavra reservada

rodei no banco assim order1 no lugar de order e funciona.

create table order1 (id bigint not null auto_increment, type varchar(255), value decimal(19,2), primary key (id)) engine=InnoDB

Oi, Mario. Obrigado pela resposta.

Em relação à porta 8080, eu estava usando-a com o Tomcat num outro projeto. Mas antes de começar este projeto que deu erro, eu desvinculei do Tomcat o projeto anterior. Então, na minha cabeça, a porta 8080 estava livre.

Faz sentido isso? Ou eu devo fazer alguma outra coisa para poder liberá-la?

Em relação ao erro no SQL, o próprio programa, com suas bibliotecas e dependências, cria as tabelas automaticamente. Não fui eu quem digitei "create table order", então não consegui pensar em como mudar isso aí que você sugeriu.

A exception fala em erro de sintaxe, mas também eu não saberia como mudar a sintaxe, já que não estou escrevendo diretamente no terminal.

Talvez mudar o nome da classe/variável com nome "Order"?

Valeu!!

Olá, Mario.

Eu alterei o que eu tinha de "order" para "order1" e agora deu certo a criação da tabela no banco de dados.

No entanto, ainda estão acontecendo o problema da porta 8080 e a exception na "thread 'task-2'", "EntityManagerFactory is closed" etc., que estavam aparecendo antes.

O que será que pode ser?

Eu ainda nem criei nada com EntityManagerFactory no projeto...

Obrigado!

Exception in thread "task-2" java.lang.IllegalStateException: EntityManagerFactory is closed
    at org.hibernate.internal.SessionFactoryImpl.validateNotClosed(SessionFactoryImpl.java:509)
    at org.hibernate.internal.SessionFactoryImpl.getProperties(SessionFactoryImpl.java:503)
    at org.springframework.boot.autoconfigure.orm.jpa.DataSourceInitializedPublisher.findDataSource(DataSourceInitializedPublisher.java:105)
    at org.springframework.boot.autoconfigure.orm.jpa.DataSourceInitializedPublisher.publishEventIfRequired(DataSourceInitializedPublisher.java:97)
    at org.springframework.boot.autoconfigure.orm.jpa.DataSourceInitializedPublisher.access$100(DataSourceInitializedPublisher.java:50)
    at org.springframework.boot.autoconfigure.orm.jpa.DataSourceInitializedPublisher$DataSourceSchemaCreatedPublisher.lambda$postProcessEntityManagerFactory$0(DataSourceInitializedPublisher.java:200)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
2020-09-28 10:05:12.413  INFO 9324 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2020-09-28 10:05:12.416  INFO 9324 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2020-09-28 10:05:12.433  INFO 9324 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
2020-09-28 10:05:12.435  INFO 9324 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-09-28 10:05:12.447  INFO 9324 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-09-28 10:05:12.451 ERROR 9324 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Web server failed to start. Port 8080 was already in use.

Action:

Identify and stop the process that's listening on port 8080 or configure this application to listen on another port.

[Atualização]

Agora eu entrei no Tomcat v9.0 vinculado ao Eclipse (que eu estava usando num outro projeto) e alterei as portas 8005 (Tomcat admin port) e 8080 (HTTP/1.1) para 8006 e 8081.

Curiosamente, a "Exception in thread "task-2" java.lang.IllegalStateException: EntityManagerFactory is closed" parou de ocorrer.

No entanto, ainda aparece a mensagem:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-09-28 10:14:20.070 ERROR 2564 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Web server failed to start. Port 8080 was already in use.

Action:

Identify and stop the process that's listening on port 8080 or configure this application to listen on another port.

Voce não esta usando o springboot?

Estou seguindo o passo-a-passo da aula. Não compreendo exatamente o quê faz o quê. Mas acho que estou usando o springboot sim, junto com o Heidi.

Mas deu certo aqui. Deletei o Tomcat da aba "Servers" no Eclipse, fui fazendo uns testes, e no fim deu certo.

Obrigado pela ajuda, Mario.

Então. O que estava ocorrendo é que o springboot tem um servidor embarcado e por padrão roda na porta 80. Voce deveria estar rodando Run as Server... em algum momento. Mas com o springboot não precisa de "um tomcat externo".

Tranquilo.