我目前使用 spring 进行依赖注入。Hibernate 使用 postgres 方言进行正常运行,但我想将 HSQL 用于 DBUnitils 数据库测试。
我的Spring-Configuration包含以下内容:
<!-- 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 资源过滤所取代。
DBUnitils 的 Spring-Configruation 包含以下内容:
<bean id="dataSource" class="org.unitils.database.UnitilsDataSourceFactoryBean"/>
</beans>
因此使用 UnitilsDataSource 覆盖我的运行配置中的数据源。
问题:我无法使用 Postgres-Dialect 对 HSQL-Test-Database 运行测试,因为某些命令不起作用。 我想到的唯一解决方案:在 maven 中切换资源过滤器,但我必须手动执行此操作(通过在每个 maven 调用上证明“-P TEST”)。那么是否有可能覆盖hibernate.dialect?
谢谢!