我正在尝试将 Struts/Spring 应用程序从 Hibernate 3.1 升级到 Hibernate 4.3。
我正在使用直到我的数据库测试,在 Hibernate 3.1 下,测试工作正常。在 Hibernate 4.3 下,测试失败并出现以下错误:
org.unitils.core.UnitilsException: Could not find a configuring @HibernateSessionFactory annotation or custom config method
at org.unitils.orm.common.OrmModule.getConfiguredPersistenceUnit(OrmModule.java:186)
at org.unitils.orm.common.OrmModule.getPersistenceUnit(OrmModule.java:147)
at org.unitils.orm.common.OrmModule.injectOrmPersistenceUnitIntoTestObject(OrmModule.java:333)
at org.unitils.orm.common.OrmModule$OrmTestListener.beforeTestSetUp(OrmModule.java:379)
at org.unitils.core.Unitils$UnitilsTestListener.beforeTestSetUp(Unitils.java:273)
at org.unitils.UnitilsJUnit4TestClassRunner$TestListenerInvokingMethodRoadie.runBeforesThenTestThenAfters(UnitilsJUnit4TestClassRunner.java:181)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:86)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
at org.unitils.UnitilsJUnit4TestClassRunner.invokeTestMethod(UnitilsJUnit4TestClassRunner.java:95)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:61)
at org.unitils.UnitilsJUnit4TestClassRunner.access$000(UnitilsJUnit4TestClassRunner.java:42)
at org.unitils.UnitilsJUnit4TestClassRunner$1.run(UnitilsJUnit4TestClassRunner.java:60)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:33)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:45)
at org.unitils.UnitilsJUnit4TestClassRunner.run(UnitilsJUnit4TestClassRunner.java:67)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
例如,以下测试将失败:
@SpringApplicationContext({ configurationFiles })
public class SettlementDAOImplTest extends UnitilsJUnit4 {
@HibernateSessionFactory
private SessionFactory sessionFactory;
@Test
public void type() throws Exception {
assertThat(SettlementDAOImpl.class, notNullValue());
}
}
我检查了我的库,并且正在加载正确版本的 Unitils 和 Hibernate,并且我的 sessionFactory 被定义为org.springframework.orm.hibernate4.LocalSessionFactoryBean
在这一点上,我什至不知道如何进行。看来 Unitils 正在寻找 hibernate3.localSessionFactoryBean。我应该寻找什么来解决这个问题?
在我的 applicationcontext 文件中, sessionFactory 看起来像:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>Settlement.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<!-- <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> -->
<prop key="hibernate.dialect">
com.acteva.commons.util.MySQLDialect
</prop>
<prop key="hibernate.bytecode.provider">javassist</prop>
<prop key="hibernate.bytecode.use_reflection_optimizer">true</prop>
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.connection.release_mode">
auto
</prop>
</props>
</property>
<property name="entityInterceptor" ref="entityInterceptorBean" />
</bean>