クラス EntityManagerFactoryUtils
java.lang.ObjectSE
org.springframework.orm.jpa.EntityManagerFactoryUtils
JPA EntityManager 処理のメソッドを備えたヘルパークラス。トランザクション内で EntityManager インスタンスを再利用できます。例外変換のサポートも提供します。
主にフレームワーク内での内部使用を目的としています。
- 導入:
- 2.0
- 作成者:
- Juergen Hoeller
フィールドのサマリー
フィールド修飾子と型フィールド説明static final intJPA EntityManagers をクリーンアップする TransactionSynchronization オブジェクトのオーダー値。コンストラクターの概要
コンストラクターメソッドのサマリー
修飾子と型メソッド説明static voidapplyTransactionTimeout(QueryEE query, EntityManagerFactoryEE emf) 現在のトランザクションタイムアウトがある場合は、指定された JPA クエリオブジェクトに適用します。static void指定された JPA EntityManager を閉じ、スローされたクリーンアップ例外をキャッチしてログに記録します。static DataAccessException指定されたランタイム例外を、org.springframework.dao階層からの適切な例外に変換します。static EntityManagerEEdoGetTransactionalEntityManager(EntityManagerFactoryEE emf, MapSE<?, ?> properties) 指定されたファクトリから JPA EntityManager を取得します。static EntityManagerEEdoGetTransactionalEntityManager(EntityManagerFactoryEE emf, MapSE<?, ?> properties, boolean synchronizedWithTransaction) 指定されたファクトリから JPA EntityManager を取得します。static EntityManagerFactoryEEfindEntityManagerFactory(ListableBeanFactory beanFactory, StringSE unitName) 指定された Spring アプリケーションコンテキスト(ListableBeanFactory で表されます)で指定された名前の EntityManagerFactory を見つけます。static EntityManagerEE指定されたファクトリから JPA EntityManager を取得します。static EntityManagerEEgetTransactionalEntityManager(EntityManagerFactoryEE emf, MapSE<?, ?> properties) 指定されたファクトリから JPA EntityManager を取得します。
フィールドの詳細
ENTITY_MANAGER_SYNCHRONIZATION_ORDER
public static final int ENTITY_MANAGER_SYNCHRONIZATION_ORDERJPA EntityManagers をクリーンアップする TransactionSynchronization オブジェクトのオーダー値。DataSourceUtils.CONNECTION_SYNCHRONIZATION_ORDER-100 を返し、EntityManager クリーンアップを実行してから JDBC 接続クリーンアップを実行します(ある場合)。
コンストラクターの詳細
EntityManagerFactoryUtils
public EntityManagerFactoryUtils()
メソッドの詳細
findEntityManagerFactory
public static EntityManagerFactoryEE findEntityManagerFactory(ListableBeanFactory beanFactory, @Nullable StringSE unitName) throws NoSuchBeanDefinitionException 指定された Spring アプリケーションコンテキスト(ListableBeanFactory で表されます)で指定された名前の EntityManagerFactory を見つけます。検出された EntityManagerFactory が
EntityManagerFactoryInfoインターフェースを実装している場合、指定されたユニット名は構成された永続性ユニットと照合されます。そうでない場合、EntityManagerFactory Bean 名がその規則に従っていると想定して、永続性ユニット名は Spring Bean 名と照合されます。ユニット名が指定されていない場合、このメソッドはデフォルトの EntityManagerFactory から
BeanFactory.getBean(Class)を検索します。- パラメーター:
beanFactory- 検索する ListableBeanFactoryunitName- 永続性ユニットの名前 (nullまたは空の場合があります。その場合、型 EntityManagerFactory の単一の Bean が検索されます。)- 戻り値:
- EntityManagerFactory
- 例外:
NoSuchBeanDefinitionException- コンテキストにそのような EntityManagerFactory がない場合- 関連事項:
getTransactionalEntityManager
@Nullable public static EntityManagerEE getTransactionalEntityManager(EntityManagerFactoryEE emf) throws DataAccessResourceFailureException 指定されたファクトリから JPA EntityManager を取得します。現在のスレッドにバインドされている対応する EntityManager を認識しています。JpaTransactionManager を使用する場合。メモ: スレッドバインドの EntityManager が見つからない場合、
nullを返します。- パラメーター:
emf- EntityManager を作成する EntityManagerFactory- 戻り値:
- EntityManager、または見つからない場合は
null - 例外:
DataAccessResourceFailureException- EntityManager を取得できなかった場合- 関連事項:
getTransactionalEntityManager
@Nullable public static EntityManagerEE getTransactionalEntityManager(EntityManagerFactoryEE emf, @Nullable MapSE<?, ?> properties) throws DataAccessResourceFailureException指定されたファクトリから JPA EntityManager を取得します。現在のスレッドにバインドされている対応する EntityManager を認識しています。JpaTransactionManager を使用する場合。メモ: スレッドバインドの EntityManager が見つからない場合、
nullを返します。- パラメーター:
emf- EntityManager を作成する EntityManagerFactoryproperties-createEntityManager呼び出しに渡されるプロパティ (nullの場合があります)- 戻り値:
- EntityManager、または見つからない場合は
null - 例外:
DataAccessResourceFailureException- EntityManager を取得できなかった場合- 関連事項:
doGetTransactionalEntityManager
@Nullable public static EntityManagerEE doGetTransactionalEntityManager(EntityManagerFactoryEE emf, MapSE<?, ?> properties) throws PersistenceExceptionEE指定されたファクトリから JPA EntityManager を取得します。現在のスレッドにバインドされている対応する EntityManager を認識しています。JpaTransactionManager を使用する場合。getEntityManagerと同じですが、元の PersistenceException をスローします。- パラメーター:
emf- EntityManager を作成する EntityManagerFactoryproperties-createEntityManager呼び出しに渡されるプロパティ (nullの場合があります)- 戻り値:
- EntityManager、または見つからない場合は
null - 例外:
PersistenceExceptionEE- EntityManager を作成できなかった場合- 関連事項:
doGetTransactionalEntityManager
@Nullable public static EntityManagerEE doGetTransactionalEntityManager(EntityManagerFactoryEE emf, @Nullable MapSE<?, ?> properties, boolean synchronizedWithTransaction) throws PersistenceExceptionEE指定されたファクトリから JPA EntityManager を取得します。現在のスレッドにバインドされている対応する EntityManager を認識しています。JpaTransactionManager を使用する場合。getEntityManagerと同じですが、元の PersistenceException をスローします。- パラメーター:
emf- EntityManager を作成する EntityManagerFactoryproperties-createEntityManager呼び出しに渡されるプロパティ (nullの場合があります)synchronizedWithTransaction- 進行中のトランザクションに自動的に参加するかどうか (JPA 2.1 SynchronizationType ルールに準拠)- 戻り値:
- EntityManager、または見つからない場合は
null - 例外:
PersistenceExceptionEE- EntityManager を作成できなかった場合- 関連事項:
applyTransactionTimeout
現在のトランザクションタイムアウトがある場合は、指定された JPA クエリオブジェクトに適用します。このメソッドは、それに応じて JPA クエリヒント "jakarta.persistence.query.timeout" を設定します。
- パラメーター:
query- JPA クエリオブジェクトemf- クエリが作成された JPA EntityManagerFactory
convertJpaAccessExceptionIfPossible
@Nullable public static DataAccessException convertJpaAccessExceptionIfPossible(RuntimeExceptionSE ex) 指定されたランタイム例外をorg.springframework.dao階層からの適切な例外に変換します。適切な変換がない場合は null を返します。他の例外はユーザーコードが原因である可能性があるため、変換しないでください。ここでは、オブジェクトが見つからない、楽観的ロックの失敗などの最も重要なケースについて説明します。より細かく変換するために、JpaTransactionManager などは JpaDialect を介した例外の高度な変換をサポートしています。
- パラメーター:
ex- 発生したランタイム例外- 戻り値:
- 対応する DataAccessException インスタンス、または例外を変換しない場合は
null
closeEntityManager
指定された JPA EntityManager を閉じ、スローされたクリーンアップ例外をキャッチしてログに記録します。- パラメーター:
em- JPA EntityManager を閉じる (nullの場合があります)- 関連事項: