0
我正在使用Spring Data。 我得到了“org.hibernate.HibernateException:当'hibernate.dialect'未设置时,连接不能为空'部署到JBoss7。 但我没有设置属性(databasePlatform - > org.hibernate.dialect.MySQL5Dialect)在我的应用程序-context.xml中:Property'hibernate.dialect'is unseen(Using Spring Data)
<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
<context:component-scan base-package="com.myproj.persistence.jpa" />
<jpa:repositories base-package="com.myproj.persistence.jpa" />
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://myhost:port/schema" />
<property name="username" value="root" />
<property name="password" value="123456" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="persistenceUnitName" value="quizPersistenceUnit"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="false"/>
<property name="database" value="MYSQL"/>
<property name="generateDdl" value="false"/>
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect"/>
</bean>
</property>
</bean>
</beans>
这是我的persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="quizPersistenceUnit">
<class>com.myproj.domain.Quiz</class>
<class>com.myproj.domain.QuizAnswer</class>
</persistence-unit>
</persistence>
然而,当我设置这个属性在persistence.xml中是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="quizPersistenceUnit">
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
</properties>
<class>com.myproj.domain.Quiz</class>
<class>com.myproj.domain.QuizAnswer</class>
</persistence-unit>
</persistence>
一切都很好。当然,我不想在persistence.xml中链接到数据库实现。
谢谢!
谢谢,但它仍然无法正常工作。这真是奇怪,因为我在diff教程中看到了相同的配置,就像这样:http://springtips.blogspot.com/2008/06/spring-entitymanagerfactory-in-jta-and.html。再次:我有你的更正相同的配置,我有persistence.xml与持久性单元(没有属性和类) – 2013-03-05 14:26:00