Lazyな関連からの取得はトランザクション境界外からしてはいけない

昨日の記事でLazyなものはエラーになってから対応すれば良いと書いたけれども、実はまずいらしいです。
JPAではトランザクション境界外でのLazyな関連の取得に関しては、出来る、出来ないに関しては定義されていないみたいです。

単純に、以下のようにだけ。

When interoperability across vendors is required, the application must not use lazy loading.
参考訳:ベンダー(プロバイダ)間での相互運用性が必要な場合はアプリケーションでは遅延ロードを使用してはいけません。

アプリケーションの可搬性を考える必要が有る場合は、エラーになったら対処するだけではなく、きちんとエラーになることも最初に確認する必要がありそうです。

Beginning Java EE 6~GlassFish 3で始めるエンタープライズJava (Programmer's SELECTION)

Beginning Java EE 6~GlassFish 3で始めるエンタープライズJava (Programmer's SELECTION)

3.2.7.2 Detached Entities and Lazy Loading
Serializing entities and merging those entities back into a persistence context may not be interoperable across vendors when lazy properties or fields and/or relationships are used.
A vendor is required to support the serialization and subsequent deserialization and merging of detached entity instances (which may contain lazy properties or fields and/or relationships that have not been fetched) back into a separate JVM instance of that vendor's runtime, where both runtime instances have access to the entity classes and any required vendor persistence implementation classes.
When interoperability across vendors is required, the application must not use lazy loading.