クラス OpenSessionInterceptor

java.lang.ObjectSE
org.springframework.orm.hibernate5.support.OpenSessionInterceptor
実装されたすべてのインターフェース:
AdviceInterceptorMethodInterceptorInitializingBean

public class OpenSessionInterceptor extends ObjectSE implements MethodInterceptor, InitializingBean
メソッドの呼び出しごとに新しい Hibernate Session をバインドする単純な AOP Alliance MethodInterceptor 実装(以前にバインドされていない場合)。

これは、MVC セットアップではなく AOP セットアップで使用するための、OpenSessionInViewInterceptor のラインに沿った単純な Hibernate セッションスコーピングインターセプターです。トランザクションに参加している場合を除いて、セッションは読み取り専用であるため、フラッシュモード "MANUAL" で新しい Session を開きます。

導入:
4.2
作成者:
Juergen Hoeller
関連事項:
  • コンストラクターの詳細

    • OpenSessionInterceptor

      public OpenSessionInterceptor()
  • メソッドの詳細

    • setSessionFactory

      public void setSessionFactory(@Nullable SessionFactory sessionFactory)
      Hibernate セッションの作成に使用する Hibernate SessionFactory を設定します。
    • getSessionFactory

      @Nullable public SessionFactory getSessionFactory()
      Hibernate セッションの作成に使用する Hibernate SessionFactory を返します。
    • afterPropertiesSet

      public void afterPropertiesSet()
      インターフェースからコピーされた説明: InitializingBean
      すべての Bean プロパティを設定し、BeanFactoryAwareApplicationContextAware などを満たした後、包含 BeanFactory によって呼び出されます。

      このメソッドにより、Bean インスタンスは、すべての Bean プロパティが設定されたときに、その全体的な構成の検証と最終的な初期化を実行できます。

      次で指定:
      インターフェース InitializingBeanafterPropertiesSet 
    • invoke

      @Nullable public ObjectSE invoke(MethodInvocation invocation) throws ThrowableSE
      インターフェースからコピーされた説明: MethodInterceptor
      このメソッドを実装して、呼び出しの前後に追加の処理を実行します。正しい実装としては、必ず Joinpoint.proceed() を呼び出すようにします。
      次で指定:
      インターフェース MethodInterceptorinvoke 
      パラメーター:
      invocation - メソッド呼び出しジョインポイント
      戻り値:
      Joinpoint.proceed() の呼び出しの結果。インターセプターによってインターセプトされる可能性があります
      例外:
      ThrowableSE - インターセプターまたはターゲットオブジェクトが例外をスローする場合
    • openSession

      protected Session openSession(SessionFactory sessionFactory) throws DataAccessResourceFailureException
      指定された SessionFactory のセッションを開きます。

      デフォルトの実装は SessionFactory.openSession() メソッドに委譲し、Session のフラッシュモードを "MANUAL" に設定します。

      パラメーター:
      sessionFactory - 使用する SessionFactory
      戻り値:
      使用するセッション
      例外:
      DataAccessResourceFailureException - セッションを作成できなかった場合
      導入:
      5.0
      関連事項: