IllegalProductException: return type must be Serializable for Hibernate SessionImpl???

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

IllegalProductException: return type must be Serializable for Hibernate SessionImpl???

DonatasCiuksys
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

IllegalProductException: return type must be Serializable for Hibernate SessionImpl???

DonatasCiuksys
Hi,

I'm using TomEE 7.0.3 WebProfile (thus latest OpenWebBeans) with Hibernate 5.2.9. I'm trying to write CDI producer for ViewScoped EntityManager:

    @PersistenceUnit
    private EntityManagerFactory emf;

    @Produces
    @ViewScoped
    private EntityManager createJTAViewScopedEntityManager() {
        return emf.createEntityManager(SynchronizationType.SYNCHRONIZED));
    }

Yet at the injection point I'm getting exception:
javax.el.ELException: javax.enterprise.inject.IllegalProductException: WebBeans producer : createJTAViewScopedEntityManager return type in the component implementation class : lt.vu.usecases.cdi.JPAResources with passivating scope @javax.faces.view.ViewScoped must be Serializable

I don't understand the reason for this exception, because Hibernate returns instance of class "SessionImpl" (as can be seen with debugger), and this class implements Serializable. What is the problem?
Reply | Threaded
Open this post in threaded view
|

Re: IllegalProductException: return type must be Serializable for Hibernate SessionImpl???

Romain Manni-Bucau
Hi

check out emf.createEntityManager(SynchronizationType.
SYNCHRONIZED)).getClass()


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://blog-rmannibucau.rhcloud.com> | Old Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2017-04-10 22:28 GMT+02:00 DonatasCiuksys <[hidden email]>:

> Hi,
>
> I'm using TomEE 7.0.3 WebProfile (thus latest OpenWebBeans) with Hibernate
> 5.2.9. I'm trying to write CDI producer for ViewScoped EntityManager:
>
>     @PersistenceUnit
>     private EntityManagerFactory emf;
>
>     @Produces
>     @ViewScoped
>     private EntityManager createJTAViewScopedEntityManager() {
>         return emf.createEntityManager(SynchronizationType.SYNCHRONIZED));
>     }
>
> Yet at the injection point I'm getting exception:
> javax.el.ELException: javax.enterprise.inject.IllegalProductException:
> WebBeans producer : createJTAViewScopedEntityManager return type in the
> component implementation class : lt.vu.usecases.cdi.JPAResources with
> passivating scope @javax.faces.view.ViewScoped must be Serializable
>
> I don't understand the reason for this exception, because Hibernate returns
> instance of class "SessionImpl" (as can be seen with debugger), and this
> class implements Serializable. What is the problem?
>
>
>
> --
> View this message in context: http://tomee-openejb.979440.n4.nabble.com/
> IllegalProductException-return-type-must-be-Serializable-for-Hibernate-
> SessionImpl-tp4681517p4681518.html
> Sent from the TomEE Dev mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: IllegalProductException: return type must be Serializable for Hibernate SessionImpl???

DonatasCiuksys
Well, I don't think this is that simple. CDI 1.2 spec chapter 6.6.5 says:

"If a producer method declares a passivating scope and doesn’t only return Serializable types at runtime, then the container must throw an IllegalProductException."

and

"If a producer field declares a passivating scope and doesn’t only contain Serializable values at runtime then the container must throw an IllegalProductException."

Especially "producer field" stresses "Serializable values", not types. And if my producer returns Hibernate SessionImpl, why would you say that it is not "Serializable type"?

"only return Serializable types at runtime" - this says to check the return value, not the method signature.

As a final point: check chapter 3.5.2. It contains this example:

 @Produces @ConversationScoped @UserDatabase
    public EntityManager create(EntityManagerFactory emf) {
        return emf.createEntityManager();
    }

It seems this is not possible with OpenWebBeans at all. I remember CDI 1.1 spec requiring to check method signatures, but 1.2 no longer says anything about method signatures, CDI must check the object that is being returned.

Donatas
Reply | Threaded
Open this post in threaded view
|

Re: IllegalProductException: return type must be Serializable for Hibernate SessionImpl???

Romain Manni-Bucau
Yes, org.apache.webbeans.component.AbstractProducerBean#checkScopeType
enforces the returned type to be serializable.

Tracked at https://issues.apache.org/jira/browse/OWB-1177


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://blog-rmannibucau.rhcloud.com> | Old Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2017-04-11 10:04 GMT+02:00 DonatasCiuksys <[hidden email]>:

> Well, I don't think this is that simple. CDI 1.2 spec chapter 6.6.5 says:
>
> "If a producer method declares a passivating scope and doesn’t only return
> Serializable types at runtime, then the container must throw an
> IllegalProductException."
>
> and
>
> "If a producer field declares a passivating scope and doesn’t only contain
> Serializable values at runtime then the container must throw an
> IllegalProductException."
>
> Especially "producer field" stresses "Serializable values", not types. And
> if my producer returns Hibernate SessionImpl, why would you say that it is
> not "Serializable type"?
>
> "only return Serializable types at runtime" - this says to check the return
> value, not the method signature.
>
> As a final point: check chapter 3.5.2. It contains this example:
>
>  @Produces @ConversationScoped @UserDatabase
>     public EntityManager create(EntityManagerFactory emf) {
>         return emf.createEntityManager();
>     }
>
> It seems this is not possible with OpenWebBeans at all. I remember CDI 1.1
> spec requiring to check method signatures, but 1.2 no longer says anything
> about method signatures, CDI must check the object that is being returned.
>
> Donatas
>
>
>
> --
> View this message in context: http://tomee-openejb.979440.n4.nabble.com/
> IllegalProductException-return-type-must-be-Serializable-for-Hibernate-
> SessionImpl-tp4681517p4681520.html
> Sent from the TomEE Dev mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: IllegalProductException: return type must be Serializable for Hibernate SessionImpl???

DonatasCiuksys
That was really fast :)
Many thanks!

Donatas