Howt to have Extended persistence context for @Stateless EJBs and POJOS

View: New views
3 Messages — Rating Filter:   Alert me  

Howt to have Extended persistence context for @Stateless EJBs and POJOS

by Francisco Peredo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi!
I while ago I posted here asking for a way to emulate FlushMode.MANUAL in EclipseLink for support
of conversational behavior, and back then I was told that:

Doug Clarke wrote:
Making changes within a entity manager acting as an extended persistence context where the complete set of conversation changes are committed in a single transaction does make sense and is very common. JPA supports this through its support for joining of an extended persistence context with a transaction.
So I went and asked about that in on the Hibernate side... And got this answer stating, basically that extended persistence contexts get broken because:

Gavin King wrote:
[...]if I call a stateless session bean, the persistence context does not propagate, so any work it does is either committed non-atomically (i.e. immediately) or not at all. Work done by stateless session beans is not able to form part of the atomic long-running optimistic "transaction".
Now... am not sure I really understand this... but my interpretation is that plain JPA only supports extended persistence contexts  in @Stateful EJBs, and if I try use an extended persistence context in @Stateless EJBs (or in plain POJOs working in a "Stateful-like" way thanks to not-standard the services provided by Spring or Seam) it will break and fail.

Did I understood correctly? And if I did : is there an EclipseLink specific extension to provide something like an extended persistence context  for POJOS (and/or  @Stateless EJBs)?

Regards,

Re: Howt to have Extended persistence context for @Stateless EJBs and POJOS

by James Sutherland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Not sure I understand but you seem to want to ignore the container JPA transactions correct?

Normally when using EJB any work you do inside a JTA transaction will be committed when that JTA transaction commits, normally at the end of the SessionBean method, or when the JTA transaction is committed explicitly.  You seem to want your EntityManager transaction to span multiple server calls, and multiple JTA transactions.  For this I think you would want to use an application managed EntityManager.  Either do not use JTA at all, just use EntityManager transactions and commit whenever you desire, or use joinTransaction() when you wish to commit to commit along with the active JTA transaction.

Francisco Peredo wrote:
Hi!
I while ago I posted here asking for a way to emulate FlushMode.MANUAL in EclipseLink for support
of conversational behavior, and back then I was told that:

Doug Clarke wrote:
Making changes within a entity manager acting as an extended persistence context where the complete set of conversation changes are committed in a single transaction does make sense and is very common. JPA supports this through its support for joining of an extended persistence context with a transaction.
So I went and asked about that in on the Hibernate side... And got this answer stating, basically that extended persistence contexts get broken because:

Gavin King wrote:
[...]if I call a stateless session bean, the persistence context does not propagate, so any work it does is either committed non-atomically (i.e. immediately) or not at all. Work done by stateless session beans is not able to form part of the atomic long-running optimistic "transaction".
Now... am not sure I really understand this... but my interpretation is that plain JPA only supports extended persistence contexts  in @Stateful EJBs, and if I try use an extended persistence context in @Stateless EJBs (or in plain POJOs working in a "Stateful-like" way thanks to not-standard the services provided by Spring or Seam) it will break and fail.

Did I understood correctly? And if I did : is there an EclipseLink specific extension to provide something like an extended persistence context  for POJOS (and/or  @Stateless EJBs)?

Regards,

Re: Howt to have Extended persistence context for @Stateless EJBs and POJOS

by Francisco Peredo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

And this application managed EntityManager will give this conversational handling of transactions even when used inside @Stateless EJBs? and if it can be used on @Stateless EJBS... Can you offer any insights on why Gavin thinks it can not be used with @Stateless EJBS? (Or am I plain interpreting him wrong?)


Not sure I understand but you seem to want to ignore the container JPA transactions correct?

Normally when using EJB any work you do inside a JTA transaction will be committed when that JTA transaction commits, normally at the end of the SessionBean method, or when the JTA transaction is committed explicitly.  You seem to want your EntityManager transaction to span multiple server calls, and multiple JTA transactions.  For this I think you would want to use an application managed EntityManager.  Either do not use JTA at all, just use EntityManager transactions and commit whenever you desire, or use joinTransaction() when you wish to commit to commit along with the active JTA transaction.

Francisco Peredo wrote:
Hi!
I while ago I posted here asking for a way to emulate FlushMode.MANUAL in EclipseLink for support
of conversational behavior, and back then I was told that:

Doug Clarke wrote:
Making changes within a entity manager acting as an extended persistence context where the complete set of conversation changes are committed in a single transaction does make sense and is very common. JPA supports this through its support for joining of an extended persistence context with a transaction.
So I went and asked about that in on the Hibernate side... And got this answer stating, basically that extended persistence contexts get broken because:

Gavin King wrote:
[...]if I call a stateless session bean, the persistence context does not propagate, so any work it does is either committed non-atomically (i.e. immediately) or not at all. Work done by stateless session beans is not able to form part of the atomic long-running optimistic "transaction".
Now... am not sure I really understand this... but my interpretation is that plain JPA only supports extended persistence contexts  in @Stateful EJBs, and if I try use an extended persistence context in @Stateless EJBs (or in plain POJOs working in a "Stateful-like" way thanks to not-standard the services provided by Spring or Seam) it will break and fail.

Did I understood correctly? And if I did : is there an EclipseLink specific extension to provide something like an extended persistence context  for POJOS (and/or  @Stateless EJBs)?

Regards,