Cosminexus V9 アプリケーションサーバ 機能解説 基本・開発編(コンテナ共通機能)

[目次][用語][索引][前へ][次へ]

5.11.4 アプリケーションサーバでJPAを使用するときの注意事項

アプリケーションが取得できるEntityManagerの型は,JPAプロバイダのEntityManagerオブジェクトではなく,アプリケーションサーバが提供するEntityManagerのプロキシクラスです。

EntityManagerオブジェクトは,インジェクション,JNDIルックアップ,またはEntityManagerFactoryで取得できます。

なお,インジェクションを使用してEntityManagerを取得する場合には,EntityManagerをインジェクトするフィールドまたはメソッド引数の型は,javax.persistence.EntityManagerにしてください。

また,インジェクション,JNDIルックアップ,またはEntityManagerFactoryで取得したEntityManagerは,JPAプロバイダのEntityManagerの実装クラスにキャストできません。

JPAプロバイダのEntityManagerオブジェクトを取得する必要がある場合は,インジェクション,JNDIルックアップ,またはEntityManagerFactoryで取得したEntityManagerプロキシオブジェクトのgetDelegateメソッドを使用してください。