Ir ao conteúdo

Java Erro ao Criar Tabela no Hibernate


Ir à solução Resolvido por Jamesplayhard,

Posts recomendados

Postado

Pessoal boa noite, estou com um problema ao criar uma tabela no banco de dados através do framework Hibernate ele cria no console quando compila, mas ao atualizar no banco de dados , nada de tabelas.Se alguém com experiência nessa área poder ajudar , agradeço desde já.

 

Olhem o processo abaixo:

mar 03, 2018 1:13:18 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager
INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
mar 03, 2018 1:13:18 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.11.Final}
mar 03, 2018 1:13:18 AM org.hibernate.cfg.Environment
INFO: HHH000206: hibernate.properties not found
mar 03, 2018 1:13:18 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
mar 03, 2018 1:13:19 AM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
mar 03, 2018 1:13:19 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
mar 03, 2018 1:13:19 AM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
mar 03, 2018 1:13:20 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
mar 03, 2018 1:13:20 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://127.0.0.1:3306/drogaria]
mar 03, 2018 1:13:20 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000046: Connection properties: {user=root, password=****}
mar 03, 2018 1:13:20 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000006: Autocommit mode: false
mar 03, 2018 1:13:20 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
Sat Mar 03 01:13:21 BRT 2018 WARN: Establishing SSL connection without server’s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn’t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false’. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
mar 03, 2018 1:13:22 AM org.hibernate.dialect.Dialect
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
mar 03, 2018 1:13:23 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
mar 03, 2018 1:13:24 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory
INFO: HHH000397: Using ASTQueryTranslatorFactory
mar 03, 2018 1:13:26 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000227: Running hbm2ddl schema export
Hibernate: drop table if exists Estado
Hibernate: create table Estado (codico bigint not null auto_increment, nome varchar(255), sigla varchar(255), primary key (codico)) type=InnoDB
mar 03, 2018 1:13:26 AM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: create table Estado (codico bigint not null auto_increment, nome varchar(255), sigla varchar(255), primary key (codico)) type=InnoDB
mar 03, 2018 1:13:26 AM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: 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 ‘type=InnoDB’ at line 1
mar 03, 2018 1:13:26 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000230: Schema export complete
mar 03, 2018 1:13:27 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH000030: Cleaning up connection pool [jdbc:mysql://127.0.0.1:3306/drogaria]

 

Olhem minha Configuração:

<hibernate-configuration>
    <session-factory>

        <!-- Configurações de Conexão com o Banco de Dados -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://127.0.0.1:3306/drogaria</property>
        <property name="connection.username">root</property>
        <property name="connection.password">q1w2e3r4</property>

        <!-- Pool de Conexões-->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>

        <!-- EGerenciamento do Contexto das Sessões-->
        <property name="current_session_context_class">thread</property>

        <!-- Cache de segundo nivel -->
        <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

        <!-- Mostra as SQLs Geradas -->
        <property name="show_sql">true</property>

        <!-- Cria as tabelas do banco -->
        <property name="hbm2ddl.auto">create</property>

      <!--  Mapeamanto das entidades  -->
<mapping class="br.pro.james.drogaria.domain.Estado"/>
    </session-factory>

</hibernate-configuration>

 

  • Solução
Postado

Descobri aonde estava o erro.

ERROR: 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 ‘type=InnoDB’ at line 1

O que Significa isso? Significa que o Hibernate estav atentando criar a tabela usando a cláusula type=InnoDB, só que a partir da versao 5.5 do Mysql essa cláusula mudou de type=InnoDB para ENGINE=INNODB.

 

E eu estou usando a versão 5.7, não sabia que a partir da 5.x mudou as cláusulas, quebrei a cabeça, mas descobri.

 

Possível Solução

Baixar a Libs mais recente do Hibernate

 

Outra possibilidade é usar o Dialeto org.hibernate.dialect.MySQLDialect, não tenho certeza mas pode ser uma solução:

 

Obs: a segunda possibilidade funcionou.


Mas obrigado pela atenção.

  • Obrigado 1

Crie uma conta ou entre para comentar

Você precisa ser um usuário para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar agora

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

LANÇAMENTO!

eletronica2025-popup.jpg


CLIQUE AQUI E BAIXE AGORA MESMO!