2012-04-11 89 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中不起作用。出於某種原因,沒有這樣的錯誤正在向我通報這一點。一旦我刪除了這個約束,一切正常!