MDP MDP - 1 month ago 4
Java Question

Caused by: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set

I uploaded my web application (Spring + Hibernate) on the server (Tomcat 7 - jdk 1.7) and I got this error:

Caused by: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set


In my computer, I have the same configuration (Spring,Hibernate, Tomcat 7, jdk 1.7, same libraries etc.) and everything works.

I looked into the internet and someone says that I need to add the
hibernate.cfg.xml
, but I never used it on my computer, and everything worked perfectly.

This is what I have in my Spring configuration file:

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan" value="com.jeansedizioni.model"/>
</bean>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${db.driver}" />
<property name="url" value="${db.url}" />
<property name="username" value="${db.user}" />
<property name="password" value="${db.pass}" />
</bean>

<bean id="applicationProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
//here are user, pass etc. for the database
<value>classpath:database.properties</value>
</list>
</property>
</bean>


Does anybody know what's my mistake?

Thank you in advance.

Answer

Define a hibernate.dialect property to your database.properties file

example:

hibernate.dialect=org.hibernate.dialect.SQLServerDialect

And add hibernateProperties to your sessionFactory bean declaration to be like this :

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
  <property name="dataSource" ref="dataSource"/>             
  <property name="packagesToScan" value="com.jeansedizioni.model"/>
  <property name="hibernateProperties">
    <props>
      <prop key="hibernate.dialect">${hibernate.dialect}</prop>
    </props>
  </property>            
</bean> 
Comments