public class GeraTabelas
{
public static void main(String[] args)
{
// Cria uma configuração para a classe Produto
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.addAnnotatedClass(Produto.class);
SchemaExport se = new SchemaExport(cfg);
se.create(true, true);
}
}[/code]
Erro
2 [main] INFO org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.4.0.GA
23 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.0.SP1
28 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
33 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
39 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
127 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.1.0.GA
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 br.com.paiter.hibernate.GeraTabelas.main(GeraTabelas.java:15)
A Lembrando já coloquei o Hibernate.properties em trocentos lugars,
Na Raiz, tá no src, tá na lib, tá na classpath… Todos outros problemas parecidos que encontrei eu tentei adaptar ao meu mas não encontrei uma resposta positiva.
Ah, como a garcia já tinha me alertado, para gerar o esquema a partir das classes anotas, vc precisa usar JPA, e usar o persistence.xml para configurar o acesso ao seu banco. O persistence.xml deve dicar dentro da pasta META-INF. Se vc tiver o plugin do JPA no Eclipse, ele já monta o esquema todo pra vc.
Aí vc coloca esse xml na sua pasta META-INF, colocando as suas informações. Vc tb precisa acrescentar um JAR do EJB pra constar o EntityManager e etc. Qq coisa é só vc ver no site do Hibernate.