3
votes

I have just read Why stateful and local anti-facades are KISS by Adam Bien where he suggests using a SFSB with an EntityManager to keep entities attached during the whole client interaction.

  1. Does't this fail not in a clustered environment as mentioned in a comment but also whenever the SFSB should be passivated by the container?

  2. If I'm right what kind of solution would you suggest? I thought to minimize the number of layers in the application it would be useful to bind the SFSBs to conversation scope and then reference them directly in my JSF views.

1
I can answer #1: yes, an extended PC will prevent passivation (and thus failover). I'm not sure how to answer #2; it's not clear to me what problem you're trying to solve. - Brett Kail
Does it matter if it's transaction-scoped or extended when it comes to passivation? I'm trying to figure out the basic design to use with EJB 3/CDI/JSF for my application. Memory consumption will probably not be a problem so I thought I would go for a "stateful" design to circumvent having to merge entities. - user953217
I guess the Tx or extended type does* matter. Take a look at EJB 3.1 FR spec. **"4.2 Conversational State of a Stateful Session Bean": "A container must not passivate a stateful session bean with an extended persistence context unless the following conditions are met: 1. All the entities in the persistence context are serializable. 2. The EntityManager is serializable." - Piotr Nowicki

1 Answers

1
votes

In general, having a stateful based architecture is counter scalable.

I have been working with EJB 3 SLSBs for over 5 years now in multiple projects and never had a real issue with merging entities.

If you want to you can decouple your client layer from your persistence layer by adding a layer of DTOs. This way you can design your entity model according to what's best for the business/persistence layer and your DTOs according to the way your client wants to present the data.

If you want to use the same objects you can still do that, you should only pay attention to which objects are "in the session" and which are detached, and you won't have any merge issues.