Hello everybody.
My configuration is:
Hibernate version: 3.2
Mapping documents: Using annotations (3.2)
Name and version of the database you are using: MySQL 5.0
I'm also using spring 2.0, jboss 4.0.5, with Eclipse IDE. I'm having a strange problem when configuring my application. I've a class to control hibernate session like the following:
Code:
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
public class HibernateUtil {
   private static final SessionFactory sessionFactory;
   static {
           try {
               sessionFactory = new AnnotationConfiguration().buildSessionFactory();
           } catch (Throwable ex) {
               // Log exception!
               throw new ExceptionInInitializerError(ex);
           }//try catch
    }//static
   public static Session getSessionFactory()
      throws HibernateException {
   return sessionFactory.openSession();
   }   
}
My configuration file:
Code:
...
<hibernate-configuration>
  <session-factory>
     <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">1</property>
    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
    
    <!-- Drop and re-create the database schema on startup -->
    <property name="hbm2ddl.auto">update</property>    
    <!-- Enable Hibernate's automatic session context management -->
    <property name="current_session_context_class">thread</property>
...
When I deploy the application and start jboss, my log has the following:
Code:
 ...
 11:09:47,890 INFO  [XmlBeanDefinitionReader] Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext-dao.xml]
 11:09:48,093 INFO  [XmlBeanDefinitionReader] Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext-jdbc.xml]
 11:09:48,109 INFO  [XmlBeanDefinitionReader] Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext-service.xml]
 ...
 11:09:48,593 INFO  [DriverManagerDataSource] Loaded JDBC driver: com.mysql.jdbc.Driver
 11:09:48,656 INFO  [Version] Hibernate Annotations 3.2.0.GA
 11:09:48,718 INFO  [Environment] Hibernate 3.2.2
 11:09:48,734 INFO  [Environment] hibernate.properties not found
 11:09:48,750 INFO  [Environment] Bytecode provider name : cglib
 11:09:48,765 INFO  [Environment] using JDK 1.4 java.sql.Timestamp handling
 11:09:49,046 INFO  [Configuration] configuring from url: jndi:/localhost/exemplo/WEB-INF/hibernate.cfg.xml
 11:09:49,250 INFO  [AnnotationConfiguration] Mapping package br.com.teste.exemplo.beans
 11:09:49,375 WARN  [AnnotationBinder] Package not found or wo package-info.java: br.com.teste.exemplo.beans
 11:09:49,484 INFO  [Configuration] Configured SessionFactory: null
 11:09:49,500 INFO  [LocalSessionFactoryBean] Building new Hibernate SessionFactory
 11:09:49,531 INFO  [AnnotationBinder] Binding entity from annotated class: br.com.teste.exemplo.beans.Usuario
 11:09:49,656 INFO  [EntityBinder] Bind entity br.com.teste.exemplo.beans.Usuario on table USUARIO
 11:09:50,406 INFO  [ConnectionProviderFactory] Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
 11:09:50,687 INFO  [SettingsFactory] RDBMS: MySQL, version: 5.0.27-community-nt
 11:09:50,687 INFO  [SettingsFactory] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.0.4 ( $Date: 2006-10-19 17:47:48 +0200 (Thu, 19 Oct 2006) $, $Revision: 5908 $ )
 11:09:50,750 INFO  [Dialect] Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
 ...
And it starts with no apparent problem. But, as soon as I try any command, like this (note: I'm starting to study Criteria, don't pay attetion to the logic =) ):
Code:
    @SuppressWarnings("unchecked")
    public List<E> list(){       
       this.session = HibernateUtil.getSessionFactory(); 
       Field[] classFields = persistenClass.getFields();
       /*Criando critério de busca para a classe*/
       Criteria criterio = session.createCriteria(persistenClass);      
       ProjectionList listaPropriedades = Projections.projectionList();
       for (Field campo : classFields){
          listaPropriedades.add(Projections.property(campo.getName()));
       }
       criterio.setProjection(listaPropriedades);
       return criterio.list();
    }
I have the following error:
Code:
11:26:01,687 ERROR [[helpdesk]] Servlet.service() for servlet exemplo threw exception
 java.lang.ExceptionInInitializerError
    at org.teste.padrao.dao.HibernateUtil.<clinit>(HibernateUtil.java:18)
 ...
 Caused by: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
which I really don't understand, since the dialect is declared in hibernate config file, just like the log points it (on the last line I showed above).
Does anyone know why this error is happening?
Thanks in advance.