JBossSeamにおけるStateful SessionBean + Extended Persistence Contextの例

JBossSeam Tutorialを見ると、Conversation contextにStateful SessionBeanをセットしています(JBoss SeamのConversation contextはServlet Sessionによって実現されています)。

Let's see how the booking example application uses a conversation-scoped stateful session bean to achieve a natural cache of persistent data related to the conversation. 

...

Example 1.9. 

@Stateful                                                                               
@Name("hotelBooking")
@Interceptor(SeamInterceptor.class)
@Conversational(ifNotBegunOutcome="main")                                                
@LoggedIn                                                                                
public class HotelBookingAction implements HotelBooking, Serializable
{
   private static final Logger log = Logger.getLogger(HotelBooking.class);

   @PersistenceContext(type=EXTENDED)                                                 
   private EntityManager bookingDatabase;
   ...

実は、Stateful SessionBeanもEntityManagerもスレッド・セーフではないという仕様ですので、Servletインスタンス変数に直接Stateful SessionBeanを格納するとアクセスごとにスレッドの同期を取る必要があります。JBoss Seamは、この問題をConversation contextにStateful SessionBeanを格納することで巧妙に回避しているように思えます。