我目前使用spring来进行注入。 Hibernate使用postgres方言进行正常运行,但我想使用HSQL进行DBUnitils数据库测试。Java:DBunitils + Spring:不同的Hibernate-Dialect
我Spring的配置包含此:
<!-- Hibernate session factory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="use_outer_join">${hibernate.use_outer_join}</prop>
<prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
<prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
<prop key="hibernate.cache.provider_class">${hibernate.cache.provider}</prop>
<prop key="hibernate.connection.pool_size">10</prop>
<prop key="hibernate.jdbc.batch_size">1000</prop>
<prop key="hibernate.bytecode.use_reflection_optimizer">true</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>de.dbruhn.relations.model.Relation</value>
<value>de.dbruhn.relations.model.RelationData</value>
<value>de.dbruhn.relations.model.RObject</value>
<value>de.dbruhn.relations.model.Type</value>
</list>
</property>
<property name="schemaUpdate" value="${hibernate.schemaUpdate}"/>
</bean>
字段得到Maven的资源过滤取代。
弹簧Configruation为DBUnitils包含此:
<bean id="dataSource" class="org.unitils.database.UnitilsDataSourceFactoryBean"/>
</beans>
,因此从与UnitilsDataSource我跑的配置将覆盖数据源。
问题:我不能使用Postgres-Dialect对HSQL测试数据库运行测试,因为有些命令不工作。 我想到的唯一解决方案是:切换maven中的资源过滤器,但我必须手工完成(通过在每个maven调用中提供“-P TEST”)。那么重写hibernate.dialect是不是有可能?
谢谢!
这对我有帮助吗?我是否必须将整个会话工厂bean复制到第二个ApplicationContext.xml?即使我将所有常量放入属性文件中,我也必须保持文件同步(例如annotatedClasses)。 – theomega 2009-09-16 20:10:16