java – 使用Spring配置的Hibernate方言问题
发布时间:2020-12-15 02:55:05 所属栏目:Java 来源:网络整理
导读:我使用 Spring配置的Hibernate(通过JPA),当我启动我的应用程序(在Tomcat 6上部署war)时,我收到此错误: org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set 这看起来很奇怪,因为我将hibernate方言设置如下: p:
我使用
Spring配置的Hibernate(通过JPA),当我启动我的应用程序(在Tomcat 6上部署war)时,我收到此错误:
org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set 这看起来很奇怪,因为我将hibernate方言设置如下: p:databasePlatform="org.hibernate.dialect.MySQL5Dialect 有关更多信息,请参阅我的完整applicationContext.xml: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" p:driverClassName="com.mysql.jdbc.Driver" p:url="jdbc:mysql://localhost/room_management" p:username="root" p:password=""/> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" p:dataSource-ref="dataSource" p:persistenceUnitName="RoomManagement"> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" p:database="MYSQL" p:databasePlatform="org.hibernate.dialect.MySQL5Dialect" p:showSql="true"/> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" p:entityManagerFactory-ref="entityManagerFactory"/> <context:annotation-config/> <context:component-scan base-package="com.parisdescartes.roommanagement.*"/> <tx:annotation-driven/> </beans> 所以,我决定在META-INF / persistence.xml文件中精确地使用Hibernate Dialect,这次是有效的.在这里我如何精确它: <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/> </properties> 你知道为什么没有使用Spring配置设置Hibernate Dialect吗? 解决方法
不确定为什么它不适用于您的配置.使用p:annotation可能出错了.我会发布我的代码(适用于我的配置),试试它是否会修复你的代码! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |