[RESOLVIDO] hibernate.properties funciona e hibernate.cfg.xml nao

4 respostas
P

Pessoal,

estou com um problema estranho aqui…

qnd eu mando rodar a classe q gera o meu banco de dados e deixo a cfg do hibernate em um arquivo hibernate.properties funciona:

hibernate.dialect org.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class org.gjt.mm.mysql.Driver
hibernate.connection.url jdbc:mysql://localhost:3306/xyz
hibernate.connection.username root
hibernate.connection.password
hibernate.show_sql true
hibernate.format_sql true

porem, qnd eu apago e deixo no arquivo .xml ele nao roda:

<?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.driver_class">org.gjt.mm.mysql.Driver</property>
         <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/xyz</property>
         <property name="hibernate.connection.username">root</property>
         <property name="hibernate.connection.password"></property>
         <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
         
     </session-factory>
 </hibernate-configuration>

ERRO:

Exception in thread "main" org.hibernate.HibernateException: The dialect was not set. Set the property hibernate.dialect. at org.hibernate.dialect.Dialect.getDialect(Dialect.java:649) at org.hibernate.dialect.Dialect.getDialect(Dialect.java:671) at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:86) at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:61) at GerarBanco.main(GerarBanco.java:9)

gostaria de saber o pq?!

estou usando annotations…

Classe gerar banco:

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

public class GerarBanco {
	public static void main(String[] args) {
		AnnotationConfiguration conf = new  AnnotationConfiguration();
		conf.addAnnotatedClass(CategoriaCliente.class);
		new SchemaExport(conf).create(true, true);
	}
}

4 Respostas

smkk

cara… verifique se o .xml está na pasta raíz… se não der certo tente tirar o “hibernate.” de todas as properties do XML…

ThiagoWorldCoder

Se a sua declaração da configuração estiver assim: Configuration.buildSessionFactory(); vc precisa mudar para Configuration.configure().buildSessionFactory(); caso o seu arquivo xml estiver em outro lugar vc coloca dentro do parênteses do configure aonde ele está!

P

ThiagoWorldCoder, eu estou executando o script para gerar o banco, como postei lá emcima…

smkk , nao adiantou retirar o prefixo…qnd eu uso o hibernate.properties ele tem o prefixo e funciona… =(

o problema para eu nao deixar o hibernate.properties é que qnd eu executo o meu ApplicationManager do mentawai tenho no meu int a criacao do meu sessionFactory…e ele busca pelo arquivo XML…tem como eu mandar ele buscar o hibernate.properties ao inves do xml??

P

Pessoal, esqueci de chamar o metodo configure();

public class GerarBanco {
	public static void main(String[] args) {
		
		 AnnotationConfiguration conf = new AnnotationConfiguration();  
		 conf.configure();
		 conf.addAnnotatedClass(CategoriaCliente.class); 
		 SchemaExport se = new SchemaExport(conf);  
		 se.create(true, true);  				   		
	}
}

[]'s

Criado 13 de janeiro de 2008
Ultima resposta 14 de jan. de 2008
Respostas 4
Participantes 3