Problem is like Romain says, @SessionScoped objects are proxied instances.
 Not real instances of the class you think they are.  To avoid this proxy,
you need to reduce your scope or directly invoke the method.  Personally, I
wouldn't share my data model with my UI (need cleaner separation, force the
application of business logic, etc); but that's just me.


On Mon, Apr 15, 2013 at 10:04 AM, <to...@orbit-x.de> wrote:

> Hi John,
>
> but i am using EJB already (User producer and async worker).
>
> Do you mean injecting producer directly and then calling
> producerInstance.produceUser()? Yes I could do that, but the effect will be
> same as omitting @SessionScoped, right?
>
> My motivation was to get jpa representation of currently logged in user,
> to pack it once into session (to minimize jdbc although i just realized
> that openjpa caches!) and to reuse it whenever i want to CRUD something
> user-related in jpa.
>
> I heard (from Struberg?) that DeltaSpike is goin to offer a solution for
> this?
>
> Br
> Reinis
>
> -----Ursprüngliche Nachricht-----
> Betreff: Re: Re[2]: JPA issue in combo with @SessionScoped
> Von: "John D. Ament" <john.d.am...@gmail.com>
> An: users@tomee.apache.org
> Datum: 2013/04/15 15:18:50
>
> The alternative is to just inject the EJB and call the method directly
> here.
>
>
> On Mon, Apr 15, 2013 at 8:14 AM, <to...@orbit-x.de> wrote:
>
> > Hi Romain,
> >
> > thanks, I already guessed something like this. But is there some pattern
> > to avoid this or work around or something I could use to make it work?
> >
> > Basically it means I may not use any cdi on jpa entities whatsoever and
> > that is quite a constraint :)
> >
> > kind regards
> > Reinis
> >
> > -----Original-Nachricht-----
> > > Von: "Romain Manni-Bucau" <rmannibu...@gmail.com>
> > > An: users@tomee.apache.org
> > > Datum: 15-04-2013 14:09
> > > Betreff: Re: JPA issue in combo with @SessionScoped
> > >
> > > a conflict between cdi and jpa
> > >
> > >
> > > proxying the jpa entity makes another class created and then the jpa
> > > provider doesn't find back your entity
> > >
> > > *Romain Manni-Bucau*
> > > *Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
> > > *Blog: **http://rmannibucau.wordpress.com/*<
> > http://rmannibucau.wordpress.com/>
> > > *LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
> > > *Github: https://github.com/rmannibucau*
> > >
> > >
> > >
> > > 2013/4/15 <to...@orbit-x.de>
> > >
> > > > Hi,
> > > > I have neither pure JPA nor CDI, nor EJB question, it's more of a
> mix:
> > > >
> > > > I have following classes (reasonably simplified)
> > > >
> > > > @javax.ejb.Stateless
> > > > public class UserProducer {
> > > >
> > > >  @PersistenceContext
> > > >  EntityManager entityManager;
> > > >
> > > >  //Achtung, it produces a SessionScoped logged in user
> > > >  @Produces @SessionScoped @my.own.LoggedIn
> > > >  public User produceUser() {
> > > >   return entityManager.createQuery(...,
> User.class).getSingleResult();
> > > >  }
> > > > }
> > > >
> > > >
> > > > @javax.ejb.Stateful
> > > > public class AsyncWorker {
> > > >
> > > >  @PersistenceContext
> > > >  EntityManager entityManager;
> > > >
> > > >  @Asynchronous
> > > >  public void invokePersist(User user) {
> > > >   schedulerEntityService.persist(user);
> > > >  }
> > > > }
> > > >
> > > > @RunWith(org.apache.openejb.junit.ApplicationComposer.class)
> > > > class IntegrationTest {
> > > >  @Inject @LoggedIn
> > > >  User user;
> > > >
> > > >  @Inject
> > > >  AsyncWorker asyncWorker;
> > > >
> > > >  @Test
> > > >  public void testIt() {
> > > >     asyncWorker.invokePersist(user); //<- No metadata was found for
> > type
> > > > "class my.own.User_$$_javassist_7". The class does not appear in the
> > list
> > > > of persistent types: [my.own.User, ...].
> > > >  }
> > > > }
> > > >
> > > > The OpenJPA throws an
> org.apache.openjpa.persistence.ArgumentException
> > No
> > > > metadata was found for type "class my.own.User_$$_javassist_7". The
> > class
> > > > does not appear in the list of persistent types: [my.own.User, ...].
> > > > FailedObject: my.own.User_$$_javassist_7-1 [java.lang.String]
> > > >
> > > > ONLY IF the producer method produceUser() is annotated as
> > @SessionScoped.
> > > > If I remove annotation, the test case works and User entity is being
> > > > persisted.
> > > >
> > > > Can anyone imagine what it could be about?
> > > >
> > > > thank you for your ideas and kind regards
> > > > Reinis
> > > >
> > > >
> > > >
> > > >
> > > >
> >
> >
> >
> >
>
>
>
>
>

Reply via email to