Re: deltaspike git commit: DELTASPIKE-1034 ActiveEntityManagerHolder needs to be Serializable

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: deltaspike git commit: DELTASPIKE-1034 ActiveEntityManagerHolder needs to be Serializable

John D. Ament
This requires entity manager to be serializable... Won't work.
On Nov 27, 2015 08:46, <[hidden email]> wrote:

> Repository: deltaspike
> Updated Branches:
>   refs/heads/master 7681a6d4d -> 74c0e3f84
>
>
> DELTASPIKE-1034 ActiveEntityManagerHolder needs to be Serializable
>
>
> Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
> Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/74c0e3f8
> Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/74c0e3f8
> Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/74c0e3f8
>
> Branch: refs/heads/master
> Commit: 74c0e3f8483e826398cc5f3491156db96b2f3b96
> Parents: 7681a6d
> Author: gpetracek <[hidden email]>
> Authored: Fri Nov 27 14:41:03 2015 +0100
> Committer: gpetracek <[hidden email]>
> Committed: Fri Nov 27 14:45:24 2015 +0100
>
> ----------------------------------------------------------------------
>  .../jpa/spi/entitymanager/ActiveEntityManagerHolder.java        | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> ----------------------------------------------------------------------
>
>
>
> http://git-wip-us.apache.org/repos/asf/deltaspike/blob/74c0e3f8/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/entitymanager/ActiveEntityManagerHolder.java
> ----------------------------------------------------------------------
> diff --git
> a/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/entitymanager/ActiveEntityManagerHolder.java
> b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/entitymanager/ActiveEntityManagerHolder.java
> index 19ee6a6..2d34582 100644
> ---
> a/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/entitymanager/ActiveEntityManagerHolder.java
> +++
> b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/entitymanager/ActiveEntityManagerHolder.java
> @@ -19,15 +19,15 @@
>  package org.apache.deltaspike.jpa.spi.entitymanager;
>
>  import javax.persistence.EntityManager;
> +import java.io.Serializable;
>
>  /**
>   * Optional holder which allows to customize the handling of the {@link
> EntityManager}.
>   * Multiple Entity-Managers with different qualifiers aren't supported.
>   * See the data-module for further details.
>   */
> -public interface ActiveEntityManagerHolder
> +public interface ActiveEntityManagerHolder extends Serializable
>  {
> -
>      void set(EntityManager entityManager);
>
>      boolean isSet();
> @@ -35,5 +35,4 @@ public interface ActiveEntityManagerHolder
>      EntityManager get();
>
>      void dispose();
> -
>  }
>
>
Reply | Threaded
Open this post in threaded view
|

Re: deltaspike git commit: DELTASPIKE-1034 ActiveEntityManagerHolder needs to be Serializable

Gerhard Petracek
Administrator
hi john,

that just means an implementation needs to rely on it or needs additional
concepts to handle it differently.
DefaultEntityManagerHolder doesn't store it at all and the only useful
implementation needed by the data-module stores it as a thread-local
(see ThreadLocalEntityManagerHolder).

regards,
gerhard



2015-11-27 14:47 GMT+01:00 John D. Ament <[hidden email]>:

> This requires entity manager to be serializable... Won't work.
> On Nov 27, 2015 08:46, <[hidden email]> wrote:
>
> > Repository: deltaspike
> > Updated Branches:
> >   refs/heads/master 7681a6d4d -> 74c0e3f84
> >
> >
> > DELTASPIKE-1034 ActiveEntityManagerHolder needs to be Serializable
> >
> >
> > Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
> > Commit:
> http://git-wip-us.apache.org/repos/asf/deltaspike/commit/74c0e3f8
> > Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/74c0e3f8
> > Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/74c0e3f8
> >
> > Branch: refs/heads/master
> > Commit: 74c0e3f8483e826398cc5f3491156db96b2f3b96
> > Parents: 7681a6d
> > Author: gpetracek <[hidden email]>
> > Authored: Fri Nov 27 14:41:03 2015 +0100
> > Committer: gpetracek <[hidden email]>
> > Committed: Fri Nov 27 14:45:24 2015 +0100
> >
> > ----------------------------------------------------------------------
> >  .../jpa/spi/entitymanager/ActiveEntityManagerHolder.java        | 5
> ++---
> >  1 file changed, 2 insertions(+), 3 deletions(-)
> > ----------------------------------------------------------------------
> >
> >
> >
> >
> http://git-wip-us.apache.org/repos/asf/deltaspike/blob/74c0e3f8/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/entitymanager/ActiveEntityManagerHolder.java
> > ----------------------------------------------------------------------
> > diff --git
> >
> a/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/entitymanager/ActiveEntityManagerHolder.java
> >
> b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/entitymanager/ActiveEntityManagerHolder.java
> > index 19ee6a6..2d34582 100644
> > ---
> >
> a/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/entitymanager/ActiveEntityManagerHolder.java
> > +++
> >
> b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/entitymanager/ActiveEntityManagerHolder.java
> > @@ -19,15 +19,15 @@
> >  package org.apache.deltaspike.jpa.spi.entitymanager;
> >
> >  import javax.persistence.EntityManager;
> > +import java.io.Serializable;
> >
> >  /**
> >   * Optional holder which allows to customize the handling of the {@link
> > EntityManager}.
> >   * Multiple Entity-Managers with different qualifiers aren't supported.
> >   * See the data-module for further details.
> >   */
> > -public interface ActiveEntityManagerHolder
> > +public interface ActiveEntityManagerHolder extends Serializable
> >  {
> > -
> >      void set(EntityManager entityManager);
> >
> >      boolean isSet();
> > @@ -35,5 +35,4 @@ public interface ActiveEntityManagerHolder
> >      EntityManager get();
> >
> >      void dispose();
> > -
> >  }
> >
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: deltaspike git commit: DELTASPIKE-1034 ActiveEntityManagerHolder needs to be Serializable

Mark Struberg
Administrator
In reply to this post by John D. Ament
Yes and no ;)

Yes, the EntityManager is not Serializable (at least almost never).
No, it is not a problem.

This class gets used and stored in the TransactionStrategy. And this is @Dependent to the TransactionInterceptor. Which is an interceptor and thus @Dependent (per spec) on the intercepted bean.

Most times the bean is an @ApplicationScoped service. But there are times when you like to annotate e.g. the action method of your @SessionScoped or @ViewAccessScoped JSF backing bean. And in that case serialisation kicks in on a clustered system.

What will happen if the setup is sane, e.g. with a @RequestScoped EntityManager (a) or an EJB PersistenceContext (b)?
In case a the injected EntityManager is only the proxy shale and thus perfectly serializable. It will also not contain any ‚active‘ EntityManager inside - because the request is over.
In case b it is almost the same. The PersistenceContext is still a proxy. The difference is that this proxy is not created by the CDI container but by the EE container or EJB integration. So all is fine as well.

If people opt to use @ConversationScoped EntityMangers, well then they are almost always broken anyway if they like to use clustering…


LieGrue,
strub


> Am 27.11.2015 um 14:47 schrieb John D. Ament <[hidden email]>:
>
> This requires entity manager to be serializable... Won't work.
> On Nov 27, 2015 08:46, <[hidden email]> wrote: