当我在下面的单元测试中尝试刷新时,我收到“无法将数据库状态与会话同步”。
任何人都可以告诉我问题是什么,因为我完全迷失了?我试过创建一个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>
答案 0 :(得分:0)
我自己设法解决了这个问题。我的CONFIG_RULE_DEFINITION有一个约束,指定Timestamp列不应该为null,并且应该默认为SYSDATE。但是,SYSDATE在我假设的HSQLDB中不起作用。由于某种原因,没有这样的错误传播通知我这个。一旦我删除了这个约束,一切正常!