java – 使用Spring配置的Hibernate方言问题

前端之家收集整理的这篇文章主要介绍了java – 使用Spring配置的Hibernate方言问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用 Spring配置的Hibernate(通过JPA),当我启动我的应用程序(在Tomcat 6上部署war)时,我收到此错误
  1. org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set

这看起来很奇怪,因为我将hibernate方言设置如下:

  1. p:databasePlatform="org.hibernate.dialect.MysqL5Dialect

有关更多信息,请参阅我的完整applicationContext.xml:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:p="http://www.springframework.org/schema/p"
  5. xmlns:context="http://www.springframework.org/schema/context"
  6. xmlns:tx="http://www.springframework.org/schema/tx"
  7. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
  8. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
  9. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
  10.  
  11.  
  12. <bean id="dataSource"
  13. class="org.springframework.jdbc.datasource.DriverManagerDataSource"
  14. p:driverClassName="com.MysqL.jdbc.Driver"
  15. p:url="jdbc:MysqL://localhost/room_management" p:username="root" p:password=""/>
  16.  
  17. <bean id="entityManagerFactory"
  18. class="org.springframework.orm.jpa.LocalContainerEntityManagerfactorybean"
  19. p:dataSource-ref="dataSource" p:persistenceUnitName="RoomManagement">
  20. <property name="jpaVendorAdapter">
  21. <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
  22. p:database="MysqL"
  23. p:databasePlatform="org.hibernate.dialect.MysqL5Dialect"
  24. p:showsql="true"/>
  25. </property>
  26. </bean>
  27.  
  28. <bean id="transactionManager"
  29. class="org.springframework.orm.jpa.JpaTransactionManager"
  30. p:entityManagerFactory-ref="entityManagerFactory"/>
  31.  
  32. <context:annotation-config/>
  33.  
  34.  
  35. <context:component-scan base-package="com.parisdescartes.roommanagement.*"/>
  36.  
  37. <tx:annotation-driven/>
  38.  
  39. </beans>

所以,我决定在Meta-INF / persistence.xml文件中精确地使用Hibernate Dialect,这次是有效的.在这里我如何精确它:

  1. <properties>
  2. <property name="hibernate.dialect"
  3. value="org.hibernate.dialect.MysqL5Dialect"/>
  4. </properties>

你知道为什么没有使用Spring配置设置Hibernate Dialect吗?

解决方法

不确定为什么它不适用于您的配置.使用p:annotation可能出错了.我会发布我的代码(适用于我的配置),试试它是否会修复你的代码

猜你在找的Java相关文章