@DeprecatedSE public abstract class SessionFactoryUtils extends ObjectSE
Spring 管理の JTA トランザクション (JtaTransactionManager を参照) と非 Spring JTA トランザクション (つまり、プレーン JTA または EJB CMT) の両方との同期をサポートし、トランザクションスコープの Hibernate セッションを透過的に提供します。非 Spring JTA トランザクションの場合、Hibernate 構成で JTA TransactionManagerLookup を指定する必要があることに注意してください。
HibernateTemplate、HibernateInterceptor、HibernateTransactionManager によって内部的に使用されます。アプリケーションコードで直接使用することもできます。
Spring 4.0 以降では Hibernate 3.6.x が必要です。
| 修飾子と型 | フィールドと説明 |
|---|---|
static int | SESSION_SYNCHRONIZATION_ORDER 使用すべきではありません。 Hibernate セッションをクリーンアップする TransactionSynchronization オブジェクトの順序値。 |
| コンストラクターと説明 |
|---|
SessionFactoryUtils() 使用すべきではありません。 |
| 修飾子と型 | メソッドと説明 |
|---|---|
static void | applyTransactionTimeout(Criteria criteria, SessionFactory sessionFactory) 使用すべきではありません。 現在のトランザクションタイムアウト(存在する場合)を指定された Hibernate 条件オブジェクトに適用します。 |
static void | applyTransactionTimeout(Query query, SessionFactory sessionFactory) 使用すべきではありません。 現在のトランザクションタイムアウト(存在する場合)を指定された Hibernate クエリオブジェクトに適用します。 |
static void | closeSession(Session session) 使用すべきではありません。 Hibernate セッションを実際に閉じて、スローされたクリーンアップ例外をキャッチしてログに記録します。 |
static DataAccessException | convertHibernateAccessException(HibernateException ex) 使用すべきではありません。 指定された HibernateException を org.springframework.dao 階層からの適切な例外に変換します。 |
static Session | doGetSession(SessionFactory sessionFactory, boolean allowCreate) 使用すべきではありません。 指定された SessionFactory の Hibernate セッションを取得します。 |
static DataSourceSE | getDataSource(SessionFactory sessionFactory) 使用すべきではありません。 指定された SessionFactory の DataSource を決定します。 |
static TransactionManagerSE | getJtaTransactionManager(SessionFactory sessionFactory, Session session) 使用すべきではありません。 指定された SessionFactory および / またはセッションから JTA TransactionManager を取得しようとします。 |
static Session | getNewSession(SessionFactory sessionFactory) 使用すべきではありません。 指定された SessionFactory から新しい Hibernate セッションを取得します。 |
static Session | getNewSession(SessionFactory sessionFactory, Interceptor entityInterceptor) 使用すべきではありません。 指定された SessionFactory から新しい Hibernate セッションを取得します。 |
static Session | getSession(SessionFactory sessionFactory, boolean allowCreate) 使用すべきではありません。 指定された SessionFactory の Hibernate セッションを取得します。 |
static Session | getSession(SessionFactory sessionFactory, Interceptor entityInterceptor, SQLExceptionTranslator jdbcExceptionTranslator) 使用すべきではありません。 指定された SessionFactory の Hibernate セッションを取得します。 |
static boolean | hasTransactionalSession(SessionFactory sessionFactory) 使用すべきではありません。 現在のスレッドにトランザクション Hibernate セッション (つまり、Spring のトランザクション機能によって現在のスレッドにバインドされたセッション) があるかどうかを返します。 |
static void | initDeferredClose(SessionFactory sessionFactory) 使用すべきではありません。 現在のスレッドと指定された SessionFactory の遅延クローズを初期化します。 |
static boolean | isDeferredCloseActive(SessionFactory sessionFactory) 使用すべきではありません。 現在のスレッドと指定された SessionFactory に対して遅延クローズがアクティブかどうかを判断します。 |
static boolean | isSessionTransactional(Session session, SessionFactory sessionFactory) 使用すべきではありません。 指定された Hibernate セッションがトランザクションであるかどうか、つまり、Spring のトランザクション機能によって現在のスレッドにバインドされているかどうかを返します。 |
static SQLExceptionTranslator | newJdbcExceptionTranslator(SessionFactory sessionFactory) 使用すべきではありません。 指定された SessionFactory に適切な SQLExceptionTranslator を作成します。 |
static void | processDeferredClose(SessionFactory sessionFactory) 使用すべきではありません。 指定された SessionFactory の延期クローズに登録されているすべての Hibernate セッションを処理します。 |
static void | releaseSession(Session session, SessionFactory sessionFactory) 使用すべきではありません。 指定されたファクトリを介して作成された指定されたセッションが外部で管理されていない場合 (つまり |
static StringSE | toString(Session session) 使用すべきではありません。 デバッグログ用に指定されたセッションを文字列化します。 |
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSEpublic static final int SESSION_SYNCHRONIZATION_ORDER
DataSourceUtils.CONNECTION_SYNCHRONIZATION_ORDER - 100 を返し、JDBC 接続のクリーンアップの前にセッションのクリーンアップを実行します(存在する場合)。public static DataSourceSE getDataSource(SessionFactory sessionFactory)
sessionFactory - チェックする SessionFactorynull SessionFactoryImplementor.getConnectionProvider(), LocalDataSourceConnectionProviderpublic static SQLExceptionTranslator newJdbcExceptionTranslator(SessionFactory sessionFactory)
sessionFactory - SessionFactory を使用して変換機を作成する getDataSource(org.hibernate.SessionFactory), SQLErrorCodeSQLExceptionTranslator, SQLStateSQLExceptionTranslatorpublic static TransactionManagerSE getJtaTransactionManager(SessionFactory sessionFactory, Session session)
sessionFactory - Hibernate SessionFactorysession - Hibernate セッション (null にもなり得る)TransactionManagerSE, SessionFactoryImplementor.getTransactionManager(), Session.getSessionFactory(), SessionFactoryImplpublic static Session getSession(SessionFactory sessionFactory, boolean allowCreate) throws DataAccessResourceFailureException, IllegalStateExceptionSE
HibernateTransactionManager を使用する場合など、現在のスレッドにバインドされている既存の対応するセッションを認識し、それを返します。それ以外の場合、"allowCreate" が true の場合は、新しいセッションが作成されます。 これは、セッションの終了時に呼び出される releaseSession と組み合わせて、一般的なデータアクセスコードで使用される getSession メソッドです。HibernateTemplate を使用すると、このようなリソース処理を気にせずにデータアクセスコードを記述できることに注意してください。
sessionFactory - Hibernate SessionFactory でセッションを作成する allowCreate - 現在のスレッドにトランザクションセッションが見つからない場合に非トランザクションセッションを作成するかどうか DataAccessResourceFailureException - セッションを作成できなかった場合 IllegalStateExceptionSE - スレッドバインドされたセッションが見つからず、"allowCreate" が false の場合 getSession(SessionFactory, Interceptor, SQLExceptionTranslator), releaseSession(org.hibernate.Session, org.hibernate.SessionFactory), HibernateTemplatepublic static Session getSession(SessionFactory sessionFactory, Interceptor entityInterceptor, SQLExceptionTranslator jdbcExceptionTranslator) throws DataAccessResourceFailureException
HibernateTransactionManager を使用する場合など、現在のスレッドにバインドされている既存の対応するセッションを認識し、それを返します。それ以外の場合は常に新しいセッションを作成します。データベースへの書き込みやデータベースからの読み取りの前にプロパティ値をインスペクションおよび変更できるセッションレベルの Hibernate エンティティインターセプターの設定をサポートします。このようなインターセプターは、SessionFactory レベル (つまり、LocalSessionFactoryBean)、HibernateTransactionManager などでも設定できます。
sessionFactory - Hibernate SessionFactory でセッションを作成する entityInterceptor - Hibernate エンティティインターセプター、またはない場合は null jdbcExceptionTranslator - トランザクション同期時にセッションをフラッシュするために使用する SQLExcepionTranslator (null の場合もあります。トランザクション同期を実際に登録するときにのみ使用されます)DataAccessResourceFailureException - セッションを作成できなかった場合 LocalSessionFactoryBean.setEntityInterceptor(org.hibernate.Interceptor), HibernateAccessor.setEntityInterceptor(org.hibernate.Interceptor)public static Session doGetSession(SessionFactory sessionFactory, boolean allowCreate) throws HibernateException, IllegalStateExceptionSE
HibernateTransactionManager を使用する場合など、現在のスレッドにバインドされている既存の対応するセッションを認識し、それを返します。それ以外の場合、"allowCreate" が true の場合は、新しいセッションが作成されます。getSession(org.hibernate.SessionFactory, boolean) とは対照的に、元の HibernateException をスローします。
sessionFactory - Hibernate SessionFactory でセッションを作成する allowCreate - 現在のスレッドにトランザクションセッションが見つからない場合に非トランザクションセッションを作成するかどうか HibernateException - セッションを作成できなかった場合 IllegalStateExceptionSE - スレッドバインドされたセッションが見つからず、allowCreate が偽の場合 public static Session getNewSession(SessionFactory sessionFactory)
トランザクション内で、このメソッドはトランザクションの JDBC 接続を共有する新しいセッションを作成します。具体的には、事前にバインドされた Hibernate セッションと同じ JDBC 接続を使用します。
sessionFactory - Hibernate SessionFactory でセッションを作成する public static Session getNewSession(SessionFactory sessionFactory, Interceptor entityInterceptor)
トランザクション内で、このメソッドはトランザクションの JDBC 接続を共有する新しいセッションを作成します。具体的には、事前にバインドされた Hibernate セッションと同じ JDBC 接続を使用します。
sessionFactory - Hibernate SessionFactory でセッションを作成する entityInterceptor - Hibernate エンティティインターセプター、またはない場合は null public static StringSE toString(Session session)
Object.toString() と同等の出力を返します: 完全修飾クラス名 + "@" + ID ハッシュコード。 これが必要な唯一の理由は、Hibernate3 の Session.toString() 実装が壊れている (そして修正されない) ためです。セッション内のすべての永続オブジェクトの toString 表現がログに記録されるため、永続オブジェクトがセッションを参照する場合 (たとえば、遅延読み込みの場合)、ConcurrentModificationExceptions が発生する可能性があります。
session - Hibernate セッションを文字列化する public static boolean hasTransactionalSession(SessionFactory sessionFactory)
sessionFactory - Hibernate SessionFactory チェックする (null の場合があります)public static boolean isSessionTransactional(Session session, SessionFactory sessionFactory)
session - 確認する Hibernate セッション sessionFactory - Hibernate SessionFactory セッションが作成された (null の場合があります)public static void applyTransactionTimeout(Query query, SessionFactory sessionFactory)
query - Hibernate クエリオブジェクト sessionFactory - クエリが作成された Hibernate SessionFactory (null の場合があります)Query.setTimeout(int)public static void applyTransactionTimeout(Criteria criteria, SessionFactory sessionFactory)
criteria - Hibernate 条件オブジェクト sessionFactory - Hibernate SessionFactory 条件は Criteria.setTimeout(int)public static DataAccessException convertHibernateAccessException(HibernateException ex)
org.springframework.dao 階層からの適切な例外に変換します。ex - 発生した HibernateExceptionHibernateAccessor.convertHibernateAccessException(org.hibernate.HibernateException), HibernateTransactionManager.convertHibernateAccessException(org.hibernate.HibernateException)public static boolean isDeferredCloseActive(SessionFactory sessionFactory)
sessionFactory - Hibernate SessionFactory をチェックする public static void initDeferredClose(SessionFactory sessionFactory)
processDeferredClose(org.hibernate.SessionFactory) 呼び出しでクローズされます。 単一セッション用に構成されていない場合に OpenSessionInViewFilter および OpenSessionInViewInterceptor によって使用されます。
sessionFactory - Hibernate SessionFactory は遅延クローズを初期化する processDeferredClose(org.hibernate.SessionFactory), releaseSession(org.hibernate.Session, org.hibernate.SessionFactory), OpenSessionInViewFilter.setSingleSession(boolean), OpenSessionInViewInterceptor.setSingleSession(boolean)public static void processDeferredClose(SessionFactory sessionFactory)
sessionFactory - Hibernate SessionFactory は延期されたクローズを処理する initDeferredClose(org.hibernate.SessionFactory), releaseSession(org.hibernate.Session, org.hibernate.SessionFactory)public static void releaseSession(Session session, SessionFactory sessionFactory)
session - 終了する Hibernate セッション (null の場合があります)sessionFactory - Hibernate SessionFactory セッションが作成された (null の場合があります)public static void closeSession(Session session)
session - 終了する Hibernate セッション (null の場合があります)Session.close()