Estou tentando usar o hibernate pra gerar as tabelas apartir das minhas classes porem quando starto o main fica dando o mesmo erro como se o hibernate não encontrasse o arquivo de configuração . Ja tentei mudar o arquivo de posicao , fiz testes e cheguei nesse resultado.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.url">jdbc:mysql://localhost/teste</property>
<!--<property name="hibernate.connection.url">jdbc:postgresql://localhost/teste</property> -->
<property name="hibernate.connection.driver.class">com.mysql.jdbc.Driver</property>
<!-- <property name="hibernate.connection.driver.class">org.postgresql.Driver.</property> -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property> -->
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">12345</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">180</property>
<property name="hibernate.c3p0.idle_test_period">100</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.EnCacheProvider</property>
<mapping class="entidades.Aluno" />
<mapping class="entidades.Curso" />
<mapping class="entidades.Matricula" />
</session-factory>
</hibernate-configuration>
package exec;
import java.io.File;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class GeraBanco {
public static void main(String[] args) {
//coloquei essa linha pra verificar se o arquivo esta sendo encontrado
System.out.println(new File("hibernate.cfg.xml").exists());
AnnotationConfiguration configuration = new AnnotationConfiguration();
SchemaExport se = new SchemaExport(configuration);
se.create(true, true);
}
}
E essa é a saida no console :
true
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.HibernateException: The dialect was not set. Set the property hibernate.dialect.
at org.hibernate.dialect.Dialect.instantiateDialect(Dialect.java:256)
at org.hibernate.dialect.Dialect.getDialect(Dialect.java:234)
at org.hibernate.dialect.Dialect.getDialect(Dialect.java:249)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:121)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:91)
at exec.GeraBanco.main(GeraBanco.java:15)
Essa é uma das minhas classes :
package entidades;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class Aluno {
@Id
@GeneratedValue
private int id;
private String nome;
private int idade;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public int getIdade() {
return idade;
}
public void setIdade(int idade) {
this.idade = idade;
}
}
O hibernate.cfg.xml esta na raiz do projeto , e eu baixei todas as libs do site do hibernate !
Alguem pode me dizer o que está errado
.
Desde ja grato .
) .