deltaspike-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Roytman <roytm...@gmail.com>
Subject Re: Transactional with extended EntityManager is not working?
Date Mon, 18 Jan 2016 03:31:26 GMT
John,

I solved it. I guess it was my inexperience with CDI. In producer I
returned my JdoEntityManagerImpl by the cretor method return type was
EntityManager not JdoEntityManager and so typecast of injected
EntityManager to JdoEntityManager failed. I assumed that proxy is build
based on injection point field type but so I was trying to inject
JdoEntityManager but it actually looks like (and it makes much more sense
as I think about it) the client proxy for injected bean is based on return
type of provider's creator method. so a small change from

@Produces
@RequestScoped
protected EntityManager create() {
  return new JdoEntityManagerImpl(gctrackJdoFactory.getPersistenceManager());
}

to

@Produces
@RequestScoped
protected JdoEntityManager create() {
  return new JdoEntityManagerImpl(gctrackJdoFactory.getPersistenceManager());
}

took care of it!

thanks again for looking into it!

if you think that @Transactional should have worked for injecting

@Inject private JdoEntityManager entityManager;

please let me know and I will experiment a bit more with it


On Sun, Jan 17, 2016 at 10:13 PM John D. Ament <johndament@apache.org>
wrote:

> I'll take a closer look tomorrow but I believe you are creating a
> non-proxyable bean here which is why interceptors aren't working.  If you
> get to it before I do, please try another interceptor on this class
>
> A proxyable bean should require a noargs constructor or one with @Inject on
> it
> On Jan 17, 2016 21:46, "Alex Roytman" <roytmana@gmail.com> wrote:
>
> > Also, @Transactional behavior seems to be such a useful thing which
> should
> > not be hardwired to EntityManager. Wouldn't it make sense to make
> > transactional resource interface be configurable so that it would be easy
> > to replicate transactional behavior for any resource as long as it
> provide
> > access to its begin/commit/rollback/rollbackOnly methods?
> >
> > On Sun, Jan 17, 2016 at 9:12 PM Alex Roytman <roytmana@gmail.com> wrote:
> >
> > > John,
> > >
> > > Here is how I create it:
> > >
> > > @ApplicationScoped
> > > public class JdoEntityManagerProducer {
> > >   private final PersistenceManagerFactory gctrackJdoFactory =
> > JDOFactory.getFactory();
> > >
> > >   @Produces
> > >   @GCTrack
> > >   @RequestScoped
> > >   protected EntityManager create() {
> > >     return new
> > JdoEntityManagerImpl(gctrackJdoFactory.getPersistenceManager());
> > >   }
> > >
> > >   protected void closeEntityManager(@Disposes @GCTrack EntityManager
> > entityManager) {
> > >     if (entityManager.isOpen()) {
> > >       entityManager.close();
> > >     }
> > >   }
> > > }
> > >
> > >
> > > here is how I inject it
> > >
> > > @Inject @GCTrack private JdoEntityManager entityManager;
> > >
> > >
> > >
> > > On Sun, Jan 17, 2016 at 6:12 PM John D. Ament <johndament@apache.org>
> > > wrote:
> > >
> > >> Hi Alex,
> > >>
> > >> Just want to check, your usecase is something like
> > >>
> > >> public interface MyEntityManager extends EntityManager {
> > >>
> > >> }
> > >>
> > >> but then how are you creating instances of this object?
> > >>
> > >> John
> > >>
> > >> On Sun, Jan 17, 2016 at 5:45 PM Alex Roytman <roytmana@gmail.com>
> > wrote:
> > >>
> > >> > It looks like of a bean is injected with a field of type not
> > >> EntityManager
> > >> > but an interface extending it, transactional annotation does not
> work.
> > >> Is
> > >> > there any way to have transactional to recognize interfaces that
> > extend
> > >> > from EntityManager
> > >> >
> > >> > Thanks
> > >> > Alex
> > >> >
> > >>
> > >
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message