2014-01-20 37 views
0

正如我打算從「hibernate3」更新到「hibernate4」&「spring 3.0.5」到「spring 3.1.4」。如何配置spring的OpenSessionInViewInterceptor的flushMode屬性3.1.4

我已經配置了OpenSessionInViewInterceptor在spring 3.0.5中,所以想在3.1.4中配置相同。

但我無法在Spring 3.1.4的OpenSessionInViewInterceptor中配置flushMode;

我對春天3.0.5以前的設置是:

<bean name="openSessionInViewInterceptor" 
     class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor"> 
     <property name="sessionFactory"> 
      <ref bean="sessionFactory" /> 
     </property> 
     <property name="flushMode"> 
      <bean 
        id="org.springframework.orm.hibernate3.HibernateAccessor.FLUSH_NEVER" 
        class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean" /> 
     </property> 
</bean> 

現在嘗試爲如下春天3.1.4配置相同:

<bean name="openSessionInViewInterceptor" 
    class="org.springframework.orm.hibernate4.support.OpenSessionInViewInterceptor"> 
    <property name="sessionFactory"> 
     <ref bean="sessionFactory" /> 
    </property> 
    <property name="flushMode"> 
     <bean 
      id="org.springframework.orm.hibernate3.HibernateAccessor.FLUSH_NEVER" 
      class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean" /> 
    </property> 
</bean> 

則拋出異常如下:

org.springframework.beans.NotWritablePropertyException: Invalid property 'flushMode' of bean class [org.springframework.orm.hibernate4.support.OpenSessionInViewInterceptor]: Bean property 'flushMode' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? 

而且在alt中找不到類似的類在春天ernate到org.springframework.orm.hibernate3.HibernateAccessor 3.1.4

所以我的問題是如何設置spring 3.1.4的OpenSessionInViewInterceptor的flushMode屬性?

回答

0

looks像一團糟,與未綁定的鏈接屬性訪問器。我猜想複製粘貼作業是在沒有考慮到不同的繼承層次結構的情況下清理東西的情況下完成的。我討厭它,當發生這種情況...

你可以使用Hibernate 3版本嗎?是的,它確實似乎在那裏;這裏是鏈接:org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor

長期來看,更仔細看看Hibernate 4代碼是否按照你的要求做了什麼,而沒有指定標誌。不幸的是,您必須忽略文檔(至少現在)並研究the source本身。

+0

雅我知道它只是一個複製粘貼,並沒有在Spring 3.1.4的OpenSessionInViewInterceptor屬性訪問器,這就是爲什麼我問一些方法來做到這一點。 其實我想將Hibernate Search集成到我的應用程序中,這就是爲什麼遷移到休眠4&spring 3.1.4。 我們可以在所有設置4版本中使用'org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor'。因爲當我試圖做到以下例外: 'java.lang.NoSuchMethodError:org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;'' – Atul

相關問題