2012-01-15 13 views
10

私は、Hibernate 3.6から4.0.1(3から3.1への春)からのアップグレードに問題があります。HibernateInterceptor(Spring 3.1とhibernate 4.01)

私はいくつかのメソッド(OnMessageコール、Cronアップデータなど)を呼び出すときにセッションを注入するためにhibernateインターセプタを使用しています。また、WebリクエストのためにOpennSessionInViewインターセプタを使用しています。 hib 3.6とspring 3.0では正常に動作していましたが、hibernate4では動作させることができません。 hibernate3パッケージでのみ使用可能なhibernateInterceptorは、それが動作しないようにします。

私は何をすべきですか?

インターセプタのものを削除すると、私は物事を開始することができますが、ウェブからの要求からdaoを呼び出すと、「セッションバインドされていない例外」が発生します。

休止状態のインターセプタを使用してDAOを傍受する方法がありますか、別の方法を使用する必要がありますか?前述のように、私はWebリクエスト(opensessioninviewでうまく処理される)、JMS OnMessage、SpringCron、および動作していない初期化コードからDAOを使用しています。

はここで休止状態インターセプタを使用した場合にスローDAOの

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" 
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" 
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:p="http://www.springframework.org/schema/p" 
xmlns:util="http://www.springframework.org/schema/util" 
xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
    http://www.springframework.org/schema/jms 
    http://www.springframework.org/schema/jms/spring-jms-3.0.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-3.0.xsd 
     http://www.springframework.org/schema/jee 
     http://www.springframework.org/schema/jee/spring-jee-3.0.xsd 
     http://www.springframework.org/schema/util 
     http://www.springframework.org/schema/util/spring-util-3.0.xsd"> 

<bean id="someDao" class="org.springframework.aop.framework.ProxyFactoryBean" 
    p:target-ref="someDaoTarget" p:proxyInterfaces="com.xxxx.MediaDataDao" 
    p:interceptorNames="hibernateInterceptor" /> 

<bean id="someDaoTarget" class="com.xxxx.SomeDaoImpl" 
    p:sessionFactory-ref="sessionFactory" /> 

<tx:annotation-driven transaction-manager="transactionManager" /> 

<bean id="transactionManager" 
class="org.springframework.orm.hibernate4.HibernateTransactionManager"> 
<property name="sessionFactory" ref="sessionFactory" /> 
</bean> 

<bean id="hibernateInterceptor" 
    class="org.springframework.orm.hibernate3.HibernateInterceptor" 
    p:sessionFactory-ref="sessionFactory" /> 

<bean id="sessionFactory" 
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" 
    destroy-method="destroy" 
    p:dataSource-ref="dataSource"> 
    <property name="packagesToScan" 
value="com.xxxx" /> 
    <property name="hibernateProperties" ref="hibernateProperties" /> 
</bean> 

<util:properties id="hibernateProperties"> 
<prop key="hibernate.hbm2dll.auto">update</prop> 
<prop key="hibernate.connection.autocommit">false</prop> 
<prop key="hibernate.show_sql">true</prop> 
<prop key="hibernate.format_sql">false</prop> 
<prop key="hibernate.jdbc.batch_size">500</prop> 
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop> 
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> 
<prop key="javax.persistence.validation.mode">callback</prop> 
</util:properties> 

例外のための基本的な設定だです:

Caused by: java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session; 
at org.springframework.orm.hibernate3.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:322) 
at org.springframework.orm.hibernate3.SessionFactoryUtils.getSession(SessionFactoryUtils.java:233) 
at org.springframework.orm.hibernate3.HibernateInterceptor.getSession(HibernateInterceptor.java:145) 
at org.springframework.orm.hibernate3.HibernateInterceptor.invoke(HibernateInterceptor.java:90) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) 
at $Proxy37.getAll(Unknown Source) 

これはバグですが、クラシックセッションはハイバネート4に存在しますか?

例外は、DAOにアクセスしようとするクラスのコンストラクタ内からスローされます。これはHibernate 3.6と完全にうまくいっていましたが、アップグレード後にはこれを動作させることができません。

答えて

3

あなたがパッケージorg.springframework.orm.hibernate4代わりのorg.springframework.orm.hibernate3

HibernateInterceptorからクラスを使用する必要があり、スプリング3.1または4.xあなたの上の休止状態4.xを使用している場合は、先に廃止されました。あなたは使用する必要がありますorg.springframework.orm.hibernate4.support.OpenSessionInterceptor

関連する問題