Ask questions and see you at March, 13th, 6.PM. CET: http://www.ustream.tv/channel/adambien
Also checkout recent episode:
Please keep the questions Java EE-stic. Means: as short and as concise as only possible. Feel free to ask several, shorter questions.
What's the recommended approach in Java EE 8 (or 7) under JAX-RS to serialise lazy JPA entities with JSON-B (or Jackson)?
Here are a few options to help with framing it.
Option 1: Inject the @PersistenceContext EntityManager in a
@Stateful
EJB and usetype = PersistenceContextType.EXTENDED
Pros: You can freely use Lazy associations under JAX-RS
Cons:
PersistenceContext
might not be compatible with theTransaction
context for other resources (Question: Any more considerations? e.g. anything more to be mindful of by changing from a Stateless to a Stateful EJB?
Option 2: Use a custom JSON-B Writer annotated with
@Transactional
and re-attach the JPA (aka JAX-RS entity) in theEntityManager
Pros: Fine grained to the JAX-RS resources.
Cons: There is a cost(?) to re-attaching entities on every response.
Question: More cons?
Option 3: Somehow(?) share the
EntityManager
across the service (request/response cycle) in a single transaction?Question: Is that possible, supported, inline with the Java EE spec?
Option 4: Use a different
EntityManager
s (e.g. one injected in a@Stateless
EJB and one in a@Stateful
withPersistenceContextType.EXTENDED
) injected in every request/response.Pros: Fine grained to the service (request/response cycle) and/or resource
Question: Can you please share an example?
Thanks!