伝統的に、私たちはs を避けよ LazyInitializationException
うとします。ただし、一時的に投げられるようにする必要があります。これは私がやろうとしていることの疑似コードです:
Session session = ...;
Customer customer = (Customer) session.get(Customer.class, 56);
// All eagerly fetched data is now in memory.
disconnectSession(session);
// Attempts to access lazy data throw LazyInitializationExceptions.
// I want to take advantage of this fact to *only* access data that
// is currently in memory.
magicallySerializeDataCurrentlyInMemory(customer);
// Now that the in-memory data has been serialized, I want to re-connect
// the session.
reconnectSession(session);
このmagicallySerializeDataCurrentlyInMemory
メソッドは、メモリ内データcustomer
とそれに関連するエンティティのシリアル化を再帰的に試行しLazyInitializationException
、途中で s を吸収します。
試み #1: session.disconnect
/session.reconnect
この試みでは、次のパターンを使用しました。
Connection connection = session.disconnect();
magicallySerializeDataCurrentlyInMemory(customer);
session.reconnect(connection);
残念ながら、それは s をスローしませんでしたLazyInitializationException
。
試み #2: session.close
/session.reconnect
この試みでは、次のパターンを使用しました。
Connection connection = session.close();
magicallySerializeDataCurrentlyInMemory(customer);
session.reconnect(connection);
残念ながら、これによりsession
after が役に立たなくなりましたsession.reconnect(connection)
。
一時的に s を強制するにはどうすればよいLazyInitializationException
ですか?