You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Karl Kildén <ka...@gmail.com> on 2014/11/20 11:39:18 UTC

ViewSscoped JSF bean & stateless that injects entityManager?

Hello,

Using TomEE 1.7.1 with JSF 2.2 I have a problem. Basically I have a bean
with javax.faces.view.ViewScoped and a Stateless that injects
EntityManager. I use Eclipselink.

This is my producer:

public class EntityManagerProducer {

@PersistenceContext(unitName = APP_NAME)
private EntityManager entityManager;

@Produces
@RequestScoped
protected EntityManager createEntityManager() {
return this.entityManager;
}
}


Passivation capable beans must satisfy passivation capable dependencies
happens pointing out my JSF bean. If I use  private transient EntityManager
em; it works but it feels strange.

Any ideas?


cheers

Re: ViewSscoped JSF bean & stateless that injects entityManager?

Posted by Karl Kildén <ka...@gmail.com>.
OK so I will refactor so my controller is @RequestScoped but this use case
should be supported in java ee imo. That is-  ViewScoped JSF bean and a
stateless that uses JPA...

Thanks for the help guys <3

On 20 November 2014 14:19, Romain Manni-Bucau <rm...@gmail.com> wrote:

> stateless != state-less ;). Stateless bean have can have a thread safe
> state. You just don't know which instance you get.
>
>
> Romain Manni-Bucau
> @rmannibucau
> http://www.tomitribe.com
> http://rmannibucau.wordpress.com
> https://github.com/rmannibucau
>
>
> 2014-11-20 14:17 GMT+01:00 Jean-Louis Monteiro <jl...@tomitribe.com>:
> > Because of clustering, passivation, etc...
> >
> > --
> > Jean-Louis Monteiro
> > http://twitter.com/jlouismonteiro
> > http://www.tomitribe.com
> >
> > On Thu, Nov 20, 2014 at 2:15 PM, Karl Kildén <ka...@gmail.com>
> wrote:
> >
> >> Why would you want your stateless to be serialized? Still not very used
> of
> >> using EJB so for me it it's not intuitive because there's no state?
> >>
> >> On 20 November 2014 14:09, Romain Manni-Bucau <rm...@gmail.com>
> >> wrote:
> >>
> >> > all EJBs are
> >> >
> >> >
> >> > Romain Manni-Bucau
> >> > @rmannibucau
> >> > http://www.tomitribe.com
> >> > http://rmannibucau.wordpress.com
> >> > https://github.com/rmannibucau
> >> >
> >> >
> >> > 2014-11-20 13:53 GMT+01:00 Karl Kildén <ka...@gmail.com>:
> >> > > Hello sorry for what might be stupid questions but are stateless
> beans
> >> > > serializable?
> >> > >
> >> > >
> >> > >
> >> > > On 20 November 2014 12:47, Romain Manni-Bucau <
> rmannibucau@gmail.com>
> >> > wrote:
> >> > >
> >> > >> Hi
> >> > >>
> >> > >> EntityManager is not serializable (its contract) so it can't be
> >> > >> injected in a passivation capable bean. fact it works with transent
> >> > >> field is cause it is serializable then.
> >> > >>
> >> > >> IIRC CDI 1.1 relaxed a bit it enforcing implementation to be
> >> > serializable.
> >> > >>
> >> > >>
> >> > >>
> >> > >> Romain Manni-Bucau
> >> > >> @rmannibucau
> >> > >> http://www.tomitribe.com
> >> > >> http://rmannibucau.wordpress.com
> >> > >> https://github.com/rmannibucau
> >> > >>
> >> > >>
> >> > >> 2014-11-20 11:39 GMT+01:00 Karl Kildén <ka...@gmail.com>:
> >> > >> > Hello,
> >> > >> >
> >> > >> > Using TomEE 1.7.1 with JSF 2.2 I have a problem. Basically I
> have a
> >> > bean
> >> > >> > with javax.faces.view.ViewScoped and a Stateless that injects
> >> > >> > EntityManager. I use Eclipselink.
> >> > >> >
> >> > >> > This is my producer:
> >> > >> >
> >> > >> > public class EntityManagerProducer {
> >> > >> >
> >> > >> > @PersistenceContext(unitName = APP_NAME)
> >> > >> > private EntityManager entityManager;
> >> > >> >
> >> > >> > @Produces
> >> > >> > @RequestScoped
> >> > >> > protected EntityManager createEntityManager() {
> >> > >> > return this.entityManager;
> >> > >> > }
> >> > >> > }
> >> > >> >
> >> > >> >
> >> > >> > Passivation capable beans must satisfy passivation capable
> >> > dependencies
> >> > >> > happens pointing out my JSF bean. If I use  private transient
> >> > >> EntityManager
> >> > >> > em; it works but it feels strange.
> >> > >> >
> >> > >> > Any ideas?
> >> > >> >
> >> > >> >
> >> > >> > cheers
> >> > >>
> >> >
> >>
>

Re: ViewSscoped JSF bean & stateless that injects entityManager?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
stateless != state-less ;). Stateless bean have can have a thread safe
state. You just don't know which instance you get.


Romain Manni-Bucau
@rmannibucau
http://www.tomitribe.com
http://rmannibucau.wordpress.com
https://github.com/rmannibucau


2014-11-20 14:17 GMT+01:00 Jean-Louis Monteiro <jl...@tomitribe.com>:
> Because of clustering, passivation, etc...
>
> --
> Jean-Louis Monteiro
> http://twitter.com/jlouismonteiro
> http://www.tomitribe.com
>
> On Thu, Nov 20, 2014 at 2:15 PM, Karl Kildén <ka...@gmail.com> wrote:
>
>> Why would you want your stateless to be serialized? Still not very used of
>> using EJB so for me it it's not intuitive because there's no state?
>>
>> On 20 November 2014 14:09, Romain Manni-Bucau <rm...@gmail.com>
>> wrote:
>>
>> > all EJBs are
>> >
>> >
>> > Romain Manni-Bucau
>> > @rmannibucau
>> > http://www.tomitribe.com
>> > http://rmannibucau.wordpress.com
>> > https://github.com/rmannibucau
>> >
>> >
>> > 2014-11-20 13:53 GMT+01:00 Karl Kildén <ka...@gmail.com>:
>> > > Hello sorry for what might be stupid questions but are stateless beans
>> > > serializable?
>> > >
>> > >
>> > >
>> > > On 20 November 2014 12:47, Romain Manni-Bucau <rm...@gmail.com>
>> > wrote:
>> > >
>> > >> Hi
>> > >>
>> > >> EntityManager is not serializable (its contract) so it can't be
>> > >> injected in a passivation capable bean. fact it works with transent
>> > >> field is cause it is serializable then.
>> > >>
>> > >> IIRC CDI 1.1 relaxed a bit it enforcing implementation to be
>> > serializable.
>> > >>
>> > >>
>> > >>
>> > >> Romain Manni-Bucau
>> > >> @rmannibucau
>> > >> http://www.tomitribe.com
>> > >> http://rmannibucau.wordpress.com
>> > >> https://github.com/rmannibucau
>> > >>
>> > >>
>> > >> 2014-11-20 11:39 GMT+01:00 Karl Kildén <ka...@gmail.com>:
>> > >> > Hello,
>> > >> >
>> > >> > Using TomEE 1.7.1 with JSF 2.2 I have a problem. Basically I have a
>> > bean
>> > >> > with javax.faces.view.ViewScoped and a Stateless that injects
>> > >> > EntityManager. I use Eclipselink.
>> > >> >
>> > >> > This is my producer:
>> > >> >
>> > >> > public class EntityManagerProducer {
>> > >> >
>> > >> > @PersistenceContext(unitName = APP_NAME)
>> > >> > private EntityManager entityManager;
>> > >> >
>> > >> > @Produces
>> > >> > @RequestScoped
>> > >> > protected EntityManager createEntityManager() {
>> > >> > return this.entityManager;
>> > >> > }
>> > >> > }
>> > >> >
>> > >> >
>> > >> > Passivation capable beans must satisfy passivation capable
>> > dependencies
>> > >> > happens pointing out my JSF bean. If I use  private transient
>> > >> EntityManager
>> > >> > em; it works but it feels strange.
>> > >> >
>> > >> > Any ideas?
>> > >> >
>> > >> >
>> > >> > cheers
>> > >>
>> >
>>

Re: ViewSscoped JSF bean & stateless that injects entityManager?

Posted by Jean-Louis Monteiro <jl...@tomitribe.com>.
well, not stateless :D


--
Jean-Louis Monteiro
http://twitter.com/jlouismonteiro
http://www.tomitribe.com

On Thu, Nov 20, 2014 at 2:17 PM, Jean-Louis Monteiro <
jlmonteiro@tomitribe.com> wrote:

> Because of clustering, passivation, etc...
>
> --
> Jean-Louis Monteiro
> http://twitter.com/jlouismonteiro
> http://www.tomitribe.com
>
> On Thu, Nov 20, 2014 at 2:15 PM, Karl Kildén <ka...@gmail.com>
> wrote:
>
>> Why would you want your stateless to be serialized? Still not very used of
>> using EJB so for me it it's not intuitive because there's no state?
>>
>> On 20 November 2014 14:09, Romain Manni-Bucau <rm...@gmail.com>
>> wrote:
>>
>> > all EJBs are
>> >
>> >
>> > Romain Manni-Bucau
>> > @rmannibucau
>> > http://www.tomitribe.com
>> > http://rmannibucau.wordpress.com
>> > https://github.com/rmannibucau
>> >
>> >
>> > 2014-11-20 13:53 GMT+01:00 Karl Kildén <ka...@gmail.com>:
>> > > Hello sorry for what might be stupid questions but are stateless beans
>> > > serializable?
>> > >
>> > >
>> > >
>> > > On 20 November 2014 12:47, Romain Manni-Bucau <rm...@gmail.com>
>> > wrote:
>> > >
>> > >> Hi
>> > >>
>> > >> EntityManager is not serializable (its contract) so it can't be
>> > >> injected in a passivation capable bean. fact it works with transent
>> > >> field is cause it is serializable then.
>> > >>
>> > >> IIRC CDI 1.1 relaxed a bit it enforcing implementation to be
>> > serializable.
>> > >>
>> > >>
>> > >>
>> > >> Romain Manni-Bucau
>> > >> @rmannibucau
>> > >> http://www.tomitribe.com
>> > >> http://rmannibucau.wordpress.com
>> > >> https://github.com/rmannibucau
>> > >>
>> > >>
>> > >> 2014-11-20 11:39 GMT+01:00 Karl Kildén <ka...@gmail.com>:
>> > >> > Hello,
>> > >> >
>> > >> > Using TomEE 1.7.1 with JSF 2.2 I have a problem. Basically I have a
>> > bean
>> > >> > with javax.faces.view.ViewScoped and a Stateless that injects
>> > >> > EntityManager. I use Eclipselink.
>> > >> >
>> > >> > This is my producer:
>> > >> >
>> > >> > public class EntityManagerProducer {
>> > >> >
>> > >> > @PersistenceContext(unitName = APP_NAME)
>> > >> > private EntityManager entityManager;
>> > >> >
>> > >> > @Produces
>> > >> > @RequestScoped
>> > >> > protected EntityManager createEntityManager() {
>> > >> > return this.entityManager;
>> > >> > }
>> > >> > }
>> > >> >
>> > >> >
>> > >> > Passivation capable beans must satisfy passivation capable
>> > dependencies
>> > >> > happens pointing out my JSF bean. If I use  private transient
>> > >> EntityManager
>> > >> > em; it works but it feels strange.
>> > >> >
>> > >> > Any ideas?
>> > >> >
>> > >> >
>> > >> > cheers
>> > >>
>> >
>>
>
>

Re: ViewSscoped JSF bean & stateless that injects entityManager?

Posted by Jean-Louis Monteiro <jl...@tomitribe.com>.
Because of clustering, passivation, etc...

--
Jean-Louis Monteiro
http://twitter.com/jlouismonteiro
http://www.tomitribe.com

On Thu, Nov 20, 2014 at 2:15 PM, Karl Kildén <ka...@gmail.com> wrote:

> Why would you want your stateless to be serialized? Still not very used of
> using EJB so for me it it's not intuitive because there's no state?
>
> On 20 November 2014 14:09, Romain Manni-Bucau <rm...@gmail.com>
> wrote:
>
> > all EJBs are
> >
> >
> > Romain Manni-Bucau
> > @rmannibucau
> > http://www.tomitribe.com
> > http://rmannibucau.wordpress.com
> > https://github.com/rmannibucau
> >
> >
> > 2014-11-20 13:53 GMT+01:00 Karl Kildén <ka...@gmail.com>:
> > > Hello sorry for what might be stupid questions but are stateless beans
> > > serializable?
> > >
> > >
> > >
> > > On 20 November 2014 12:47, Romain Manni-Bucau <rm...@gmail.com>
> > wrote:
> > >
> > >> Hi
> > >>
> > >> EntityManager is not serializable (its contract) so it can't be
> > >> injected in a passivation capable bean. fact it works with transent
> > >> field is cause it is serializable then.
> > >>
> > >> IIRC CDI 1.1 relaxed a bit it enforcing implementation to be
> > serializable.
> > >>
> > >>
> > >>
> > >> Romain Manni-Bucau
> > >> @rmannibucau
> > >> http://www.tomitribe.com
> > >> http://rmannibucau.wordpress.com
> > >> https://github.com/rmannibucau
> > >>
> > >>
> > >> 2014-11-20 11:39 GMT+01:00 Karl Kildén <ka...@gmail.com>:
> > >> > Hello,
> > >> >
> > >> > Using TomEE 1.7.1 with JSF 2.2 I have a problem. Basically I have a
> > bean
> > >> > with javax.faces.view.ViewScoped and a Stateless that injects
> > >> > EntityManager. I use Eclipselink.
> > >> >
> > >> > This is my producer:
> > >> >
> > >> > public class EntityManagerProducer {
> > >> >
> > >> > @PersistenceContext(unitName = APP_NAME)
> > >> > private EntityManager entityManager;
> > >> >
> > >> > @Produces
> > >> > @RequestScoped
> > >> > protected EntityManager createEntityManager() {
> > >> > return this.entityManager;
> > >> > }
> > >> > }
> > >> >
> > >> >
> > >> > Passivation capable beans must satisfy passivation capable
> > dependencies
> > >> > happens pointing out my JSF bean. If I use  private transient
> > >> EntityManager
> > >> > em; it works but it feels strange.
> > >> >
> > >> > Any ideas?
> > >> >
> > >> >
> > >> > cheers
> > >>
> >
>

Re: ViewSscoped JSF bean & stateless that injects entityManager?

Posted by Karl Kildén <ka...@gmail.com>.
Why would you want your stateless to be serialized? Still not very used of
using EJB so for me it it's not intuitive because there's no state?

On 20 November 2014 14:09, Romain Manni-Bucau <rm...@gmail.com> wrote:

> all EJBs are
>
>
> Romain Manni-Bucau
> @rmannibucau
> http://www.tomitribe.com
> http://rmannibucau.wordpress.com
> https://github.com/rmannibucau
>
>
> 2014-11-20 13:53 GMT+01:00 Karl Kildén <ka...@gmail.com>:
> > Hello sorry for what might be stupid questions but are stateless beans
> > serializable?
> >
> >
> >
> > On 20 November 2014 12:47, Romain Manni-Bucau <rm...@gmail.com>
> wrote:
> >
> >> Hi
> >>
> >> EntityManager is not serializable (its contract) so it can't be
> >> injected in a passivation capable bean. fact it works with transent
> >> field is cause it is serializable then.
> >>
> >> IIRC CDI 1.1 relaxed a bit it enforcing implementation to be
> serializable.
> >>
> >>
> >>
> >> Romain Manni-Bucau
> >> @rmannibucau
> >> http://www.tomitribe.com
> >> http://rmannibucau.wordpress.com
> >> https://github.com/rmannibucau
> >>
> >>
> >> 2014-11-20 11:39 GMT+01:00 Karl Kildén <ka...@gmail.com>:
> >> > Hello,
> >> >
> >> > Using TomEE 1.7.1 with JSF 2.2 I have a problem. Basically I have a
> bean
> >> > with javax.faces.view.ViewScoped and a Stateless that injects
> >> > EntityManager. I use Eclipselink.
> >> >
> >> > This is my producer:
> >> >
> >> > public class EntityManagerProducer {
> >> >
> >> > @PersistenceContext(unitName = APP_NAME)
> >> > private EntityManager entityManager;
> >> >
> >> > @Produces
> >> > @RequestScoped
> >> > protected EntityManager createEntityManager() {
> >> > return this.entityManager;
> >> > }
> >> > }
> >> >
> >> >
> >> > Passivation capable beans must satisfy passivation capable
> dependencies
> >> > happens pointing out my JSF bean. If I use  private transient
> >> EntityManager
> >> > em; it works but it feels strange.
> >> >
> >> > Any ideas?
> >> >
> >> >
> >> > cheers
> >>
>

Re: ViewSscoped JSF bean & stateless that injects entityManager?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
all EJBs are


Romain Manni-Bucau
@rmannibucau
http://www.tomitribe.com
http://rmannibucau.wordpress.com
https://github.com/rmannibucau


2014-11-20 13:53 GMT+01:00 Karl Kildén <ka...@gmail.com>:
> Hello sorry for what might be stupid questions but are stateless beans
> serializable?
>
>
>
> On 20 November 2014 12:47, Romain Manni-Bucau <rm...@gmail.com> wrote:
>
>> Hi
>>
>> EntityManager is not serializable (its contract) so it can't be
>> injected in a passivation capable bean. fact it works with transent
>> field is cause it is serializable then.
>>
>> IIRC CDI 1.1 relaxed a bit it enforcing implementation to be serializable.
>>
>>
>>
>> Romain Manni-Bucau
>> @rmannibucau
>> http://www.tomitribe.com
>> http://rmannibucau.wordpress.com
>> https://github.com/rmannibucau
>>
>>
>> 2014-11-20 11:39 GMT+01:00 Karl Kildén <ka...@gmail.com>:
>> > Hello,
>> >
>> > Using TomEE 1.7.1 with JSF 2.2 I have a problem. Basically I have a bean
>> > with javax.faces.view.ViewScoped and a Stateless that injects
>> > EntityManager. I use Eclipselink.
>> >
>> > This is my producer:
>> >
>> > public class EntityManagerProducer {
>> >
>> > @PersistenceContext(unitName = APP_NAME)
>> > private EntityManager entityManager;
>> >
>> > @Produces
>> > @RequestScoped
>> > protected EntityManager createEntityManager() {
>> > return this.entityManager;
>> > }
>> > }
>> >
>> >
>> > Passivation capable beans must satisfy passivation capable dependencies
>> > happens pointing out my JSF bean. If I use  private transient
>> EntityManager
>> > em; it works but it feels strange.
>> >
>> > Any ideas?
>> >
>> >
>> > cheers
>>

Re: ViewSscoped JSF bean & stateless that injects entityManager?

Posted by Karl Kildén <ka...@gmail.com>.
Hello sorry for what might be stupid questions but are stateless beans
serializable?



On 20 November 2014 12:47, Romain Manni-Bucau <rm...@gmail.com> wrote:

> Hi
>
> EntityManager is not serializable (its contract) so it can't be
> injected in a passivation capable bean. fact it works with transent
> field is cause it is serializable then.
>
> IIRC CDI 1.1 relaxed a bit it enforcing implementation to be serializable.
>
>
>
> Romain Manni-Bucau
> @rmannibucau
> http://www.tomitribe.com
> http://rmannibucau.wordpress.com
> https://github.com/rmannibucau
>
>
> 2014-11-20 11:39 GMT+01:00 Karl Kildén <ka...@gmail.com>:
> > Hello,
> >
> > Using TomEE 1.7.1 with JSF 2.2 I have a problem. Basically I have a bean
> > with javax.faces.view.ViewScoped and a Stateless that injects
> > EntityManager. I use Eclipselink.
> >
> > This is my producer:
> >
> > public class EntityManagerProducer {
> >
> > @PersistenceContext(unitName = APP_NAME)
> > private EntityManager entityManager;
> >
> > @Produces
> > @RequestScoped
> > protected EntityManager createEntityManager() {
> > return this.entityManager;
> > }
> > }
> >
> >
> > Passivation capable beans must satisfy passivation capable dependencies
> > happens pointing out my JSF bean. If I use  private transient
> EntityManager
> > em; it works but it feels strange.
> >
> > Any ideas?
> >
> >
> > cheers
>

Re: ViewSscoped JSF bean & stateless that injects entityManager?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

EntityManager is not serializable (its contract) so it can't be
injected in a passivation capable bean. fact it works with transent
field is cause it is serializable then.

IIRC CDI 1.1 relaxed a bit it enforcing implementation to be serializable.



Romain Manni-Bucau
@rmannibucau
http://www.tomitribe.com
http://rmannibucau.wordpress.com
https://github.com/rmannibucau


2014-11-20 11:39 GMT+01:00 Karl Kildén <ka...@gmail.com>:
> Hello,
>
> Using TomEE 1.7.1 with JSF 2.2 I have a problem. Basically I have a bean
> with javax.faces.view.ViewScoped and a Stateless that injects
> EntityManager. I use Eclipselink.
>
> This is my producer:
>
> public class EntityManagerProducer {
>
> @PersistenceContext(unitName = APP_NAME)
> private EntityManager entityManager;
>
> @Produces
> @RequestScoped
> protected EntityManager createEntityManager() {
> return this.entityManager;
> }
> }
>
>
> Passivation capable beans must satisfy passivation capable dependencies
> happens pointing out my JSF bean. If I use  private transient EntityManager
> em; it works but it feels strange.
>
> Any ideas?
>
>
> cheers