tôi sử dụng Hibernate (thông qua JPA) cấu hình bởi mùa xuân và khi tôi khởi động ứng dụng của tôi (chiến tranh được triển khai trên Tomcat 6), tôi nhận được lỗi này:Hibernate phương ngữ vấn đề với cấu hình Spring
org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set
Nó có vẻ lạ vì tôi 've thiết lập các phương ngữ ngủ đông như sau:
p:databasePlatform="org.hibernate.dialect.MySQL5Dialect
Để biết thêm thông tin, đây applicationContext.xml đầy đủ của tôi:
<?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>
Vì vậy, tôi đã quyết định chính xác Hibernate Dialect trong tệp META-INF/persistence.xml và lần này hoạt động. Dưới đây là cách tôi đặt trước:
<properties>
<property name="hibernate.dialect"
value="org.hibernate.dialect.MySQL5Dialect"/>
</properties>
Bạn có biết tại sao Hibernate Dialect không được đặt bằng cấu hình Spring không?
Làm thế nào để bạn xây dựng nhà máy phiên của bạn? – Bitmap
Tôi chỉ sử dụng chú thích @PersistenceContext trên tài liệu tham chiếu entityManager – Mik378