2012-04-11 69 views
0

“无法同步与会话数据库状态”我收到了“无法与会话同步数据库状态”当我在我下面的单元测试尝试刷新。休眠:在冲洗

谁能告知问题是什么,因为我完全失去了?我尝试过创建一个没有设置任何属性的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

你有一个逆映射到** ** RuleDefinition从** **的ConfigAttribute或**调整**? – ManuPK 2012-04-11 13:18:42

回答

0

的片断我已经成功地解决了这个自己。我的CONFIG_RULE_DEFINITION有一个约束,指定Timestamp列不应该为空,并且应该默认为SYSDATE。但是,SYSDATE在我假定的HSQLDB中不起作用。出于某种原因,没有这样的错误正在向我通报这一点。一旦我删除了这个约束,一切正常!