[RESOLVIDO] Erro Hibernate - Dialect

7 respostas
E

Olá galera, eu uma classe p/ gerar tabelas p/ mim.
Ocorre que, quando executo a classe, aparece uma menssagem no console dizendo que tem um erro na minha SQL syntax.
Bom, vamos ao Erro gerado no console

14:53:07  INFO [Version             ] Hibernate Annotations 3.4.0.GA
14:53:07  INFO [Environment         ] Hibernate 3.3.2.GA
14:53:07  INFO [Environment         ] hibernate.properties not found
14:53:07  INFO [Environment         ] Bytecode provider name : javassist
14:53:07  INFO [Environment         ] using JDK 1.4 java.sql.Timestamp handling
14:53:07  INFO [Version             ] Hibernate Commons Annotations 3.1.0.GA
14:53:07  INFO [Configuration       ] configuring from resource: /hibernate.cfg.xml
14:53:07  INFO [Configuration       ] Configuration resource: /hibernate.cfg.xml
14:53:08  INFO [Configuration       ] Configured SessionFactory: null
14:53:08  INFO [Dialect             ] Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
14:53:08  INFO [AnnotationBinder    ] Binding entity from annotated class: br.com.perfaco.classes.Cliente
14:53:08  INFO [EntityBinder        ] Bind entity br.com.perfaco.classes.Cliente on table Cliente
14:53:08  INFO [AnnotationConfiguration] Hibernate Validator not found: ignoring
14:53:08  INFO [SchemaExport        ] Running hbm2ddl schema export
14:53:08  INFO [SchemaExport        ] exporting generated schema to database
14:53:08  INFO [DriverManagerConnectionProvider] Using Hibernate built-in connection pool (not for production use!)
14:53:08  INFO [DriverManagerConnectionProvider] Hibernate connection pool size: 20
14:53:08  INFO [DriverManagerConnectionProvider] autocommit mode: false
14:53:08  INFO [DriverManagerConnectionProvider] using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/perfaco
14:53:08  INFO [DriverManagerConnectionProvider] connection properties: {user=root, password=****}

    drop table if exists Cliente

    create table Cliente (
        id bigint not null auto_increment,
        endereco varchar(255),
        nome varchar(255),
        telefone varchar(255),
        primary key (id)
    ) type=InnoDB
14:53:08 ERROR [SchemaExport        ] Unsuccessful: create table Cliente (id bigint not null auto_increment, endereco varchar(255), nome varchar(255), telefone varchar(255), primary key (id)) type=InnoDB
14:53:08 ERROR [SchemaExport        ] 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
14:53:08  INFO [SchemaExport        ] schema export complete
14:53:08  INFO [DriverManagerConnectionProvider] cleaning up connection pool: jdbc:mysql://localhost:3306/perfaco
Como podem ver, nao é nem um erro, ele simplesmente da uma menssagem de Unsuccessful, e nao cria a minha tabela. A classe que gera a tabela é a seguinte:
package br.com.perfaco.classes;

import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

public class GeraTabelas {
	public static void main(String args[]){
		AnnotationConfiguration cfg = new AnnotationConfiguration();
		cfg.configure();
		
		SchemaExport se = new SchemaExport(cfg);
		se.create(true, true);
		
		
		
		
	}
		
	
}
E a minha "tabela" é a seguinte:
package br.com.perfaco.classes;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
public class Cliente {
	
	@Id
	@GeneratedValue
	private Long id;
	String nome, telefone, endereco;
	
	
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public String getNome() {
		return nome;
	}
	public void setNome(String nome) {
		this.nome = nome;
	}
	public String getTelefone() {
		return telefone;
	}
	public void setTelefone(String telefone) {
		this.telefone = telefone;
	}
	public String getEndereco() {
		return endereco;
	}
	public void setEndereco(String endereco) {
		this.endereco = endereco;
	}
	
	

}

E meu arquivo hibernate.cfg

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
	<session-factory>
		
		<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
		<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/perfaco</property>
		<property name="hibernate.connection.username">root</property>
		<property name="hibernate.connection.password">root</property>
		<property name="hibernate.show_sql">true</property>
		<property name="hibernate.format_sql">true</property>
		<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>

		<mapping class="br.com.perfaco.classes.Cliente"/>

	
	</session-factory>
</hibernate-configuration>

Gostaria que a galera do guj me desse + uma força ai :D

Obrigado a todos

7 Respostas

Hebert_Coelho

Qual o seu banco de dados?

CharlesAlves

A propriedade hibernate.dialect tah errada o correto pra o mysql é a org.hibernate.dialect.MySQLDialect só é substituir que vai dar certo

E

Opa, problema resolvido.

  • uma vez o Charles me dando uma força.
    Nao respondi antes pq eu tava on no serviço.
    Valeu a ajuda de novo
D

Opa!! Resolveu meu problema também para rodar um projeto parecido no Windows, com BD MySQL.

Um projeto, ao ser rodado no Linux Ubuntu, com o dialect configurado em “org.hibernate.dialect.MySQLInnoDBDialect”, funcionou perfeito. Criou a tabela numa boa, assim como adicionou e fez consulta com o Hibernate.

Mas ao rodar este mesmo projeto no Windows 7, estava dando o mesmo erro apresentado no início deste chamado.
ERROR [SchemaExport] Unsuccessful: create table Produto (id bigint not null auto_increment, descricao varchar(255), nome varchar(255), preco double precision not null, primary key (id)) type=InnoDB
ERROR [SchemaExport] 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

Resolvido ao mudar o dialect para “org.hibernate.dialect.MySQLDialect” no Windows.

Não é a primeira vez que tenho problemas desse tipo, em que um determinado projeto funciona no Windows e no Linux não e vice-versa.
Tem sempre uma besteira/pendência ou outra para se resolver.

Abraço!

demoraisjunior

Charles e quando você for criar tabelas com relacionamentos através do seu modelo, não vai precisar que essas seja do tipo InnoDB?

demoraisjunior

Resolvi aqui …

é só chamar o MySQ5 fica assim:

hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
GilCezar

Ok, Me ajudou tambem.

Estou usando o Win7 e com as dicas do demoraisjunior e do CharlesAlves funcionaram perfeitamente.

Obrigado.

Criado 29 de novembro de 2011
Ultima resposta 17 de dez. de 2012
Respostas 7
Participantes 6