Hi all,
Does anyone know how to avoid LazyInitializationException when sending Entities back through Seam Web Remoting?
In my use case, I have a SLSB with WebRemote-able methods and a typical object graph. Like this:
@Local
public interface HouseAction {
@WebRemote public House geHouse(long houseId)
}
The house entity object itself has one-to-many with Room objects. All getters in House and Room object are WebRemote-able
This method below returns a LazyInitializationException when called from Web Remoting since the Rooms haven't been initialized yet and there wasn't any sessions to do it:
public House getHouse(long houseId) {
House house= em.find(House.class, houseId);
return House
}
What would be the proper way to avoid this? Is a conversation scope required to accomplish this? If yes, where should it begin and end?
Thanks for all your help!
thanks!
If you want the rooms to be returned, then make sure you force them to load during your method (house.getRooms().size() should work), otherwise if you don't want them then use something like:
@WebRemote(exclude = "rooms")