【问题标题】:Caused by: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set引起:org.hibernate.HibernateException:必须显式设置休眠方言
【发布时间】:2017-02-28 20:52:38
【问题描述】:

我在服务器(Tomcat 7 - jdk 1.7)上上传了我的 Web 应用程序(Spring + Hibernate),但出现了这个错误:

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

在我的计算机上,我有相同的配置(Spring、Hibernate、Tomcat 7、jdk 1.7、相同的库等)并且一切正常。

我查看了互联网,有人说我需要添加hibernate.cfg.xml,但我从未在我的计算机上使用它,并且一切正常。

这是我的 Spring 配置文件中的内容:

<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>  

有人知道我的错误是什么吗?

提前谢谢你。

【问题讨论】:

    标签: java hibernate spring-mvc tomcat7


    【解决方案1】:

    为您的database.properties 文件定义一个hibernate.dialect 属性

    示例:

    hibernate.dialect=org.hibernate.dialect.SQLServerDialect
    

    并将hibernateProperties 添加到您的sessionFactory bean 声明中,如下所示:

    <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> 
    

    【讨论】:

      【解决方案2】:

      在您的&lt;bean id="sessionFactory"&gt; 中添加此属性:

      <property name="hibernateProperties">
          <props>
              <prop key="hibernate.dialect">${hibernate.dialect}</prop>
              <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
              <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>             
          </props>
      </property>
      

      然后在你的配置文件中(你正在获取用户、密码、url)中提到方言,如下所示:

      hibernate.dialect=org.hibernate.dialect.OracleDialect
      hibernate.show_sql=true
      hibernate.hbm2ddl.auto=update
      

      【讨论】:

        猜你喜欢
        • 2023-03-19
        • 2018-10-21
        • 1970-01-01
        • 2023-03-23
        • 2015-07-26
        • 2015-01-04
        • 2013-10-26
        • 2012-07-14
        • 1970-01-01
        相关资源
        最近更新 更多