当我在下面的单元测试中尝试刷新时,我收到“无法将数据库状态与会话同步”。
谁能告诉我问题是什么,因为我完全迷路了?我试过只创建一个没有任何属性集的 RuleDefinition,但这也不起作用。
谢谢
这是我的单元测试的片段,它扩展了 AbstractTransactionalDataSourceSpringContextTests
@Test
public void testCreateRule() {
RuleDefinition ruleReturned = (RuleDefinition) hibernateRuleDefinitionDao.findRule(1);
RuleDefinition newRule = new RuleDefinition();
newRule.setCurrentState("ACTIVE");
newRule.setAttribute(ruleReturned.getSecondaryAttribute());
newRule.setSecondaryAttribute(ruleReturned.getAttribute());
newRule.setOperator(ruleReturned.getOperator());
newRule.setPrecedence(4);
hibernateRuleDefinitionDao.createRule(newRule);
// Exception is thrown after the flush
hibernateTemplate.flush();
}
DAO 方法只是调用一个保存操作。这是我的映射文件
<class name="abc.def.rules.RuleDefinition" table="REFDATA.CONFIG_RULE_DEFINITION">
<id name="ruleId" column="RULE_ID">
<generator class="increment"/>
</id>
<many-to-one name="attribute" cascade="none" class="abc.def.rules.ConfigAttribute" lazy="false" column="CONFIG_ATTR_ID"/>
<many-to-one name="operator" cascade="none" class="abc.def.rules.Operator" lazy="false">
<column name="OPRTR_VAL"/>
<column name="OPRTR_VAL_DATA_TYP"/>
</many-to-one>
<many-to-one name="secondaryAttribute" cascade="none" class="abc.def.rules.ConfigAttribute" lazy="false" column="CONFIG_ATTR_ID_2" not-null="false"/>
<property name="operand" column="OPRND_VAL" type="string"/>
<property name="trueAction" column="TRUE_ACTN" type="string"/>
<property name="falseAction" column="FALSE_ACTN" type="string"/>
<property name="precedence" column="RULE_ORD_SEQ" type="int" not-null="true"/>
<property name="currentState" column="RULE_STAT" type="string"/>
</class>
这是我的 Spring 配置文件的片段
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:mem:testdb" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocations">
<list>
<value>classpath:abc\def\hibernate-reference.cfg.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.HSQLDialect
</prop>
<prop key="hibernate.cache.provider_class">
org.hibernate.cache.NoCacheProvider
</prop>
<prop key="hibernate.cache.use_second_level_cache">
false
</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
</props>
</property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>