You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@deltaspike.apache.org by Alex Roytman <ro...@gmail.com> on 2016/01/17 23:44:55 UTC

Transactional with extended EntityManager is not working?

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

Re: Transactional with extended EntityManager is not working?

Posted by Alex Roytman <ro...@gmail.com>.
Hello Gerhard,

thank you for the reference. I've read it but my problem is right here as
 described in this article:

As you see the usage is the same. You *do not* have to use
ExtendedEntityManager at the injection point. It is just needed in the
producer-method:

I do need to use not only my own implementation of EntityManager but also
my own interface extending EntityManager and when II use it, transactional
interceptor does not seem to recognize it

the reason I need to extend EntityManager interface is that I need to
access few of my own methods on it and when injecting it I can't get to
them in the implementation class via field injected as EntityManager (it is
proxied and only recognizes interface methods and of course there is not
way to typecast it)

To give you some background on what I am trying to do:

I need to gradually transition an application written a while ago using JDO
as persistence. It is a pretty sophisticated domain model, several modules
with lots of logic baked into it. We do not want to rewrite it at the
moment but we want too take advantage of @Transactional semantic and also
 wrap it into entity manager so we can do access as much of JDO
functionality via EntityManager as possible (pretty much majority can be
done but for queries) as a way to gradually move to JPA and eventually
remove JDO (sad - it was a great spec with some excellent commercial
implementations still superior to JPA but unfortunatelly killed and dead)

Anyway, I would like to extent EntityManager interface with one method
getJdo() while implementing as many EntityManager method to delegate to
wrapped JDO PersistenceManager instance. I need getJdo() because we can't
quite wrap all JDO functionality and need access to the underlying
EntityManager's JDO PersistenceManager instance.

Everything works fine except that if I inject

@Inject private EntityManager entityManager;

into my bean I can't get to getJdo()

if I inject it as

@Inject private JdoEntityManager entityManager;

@Transactional stops working

Thanks,
Alex


On Sun, Jan 17, 2016 at 6:07 PM Gerhard Petracek <ge...@gmail.com>
wrote:

> hi alex,
>
> please have a look at [1].
>
> regards,
> gerhard
>
> [1]
>
> http://deltaspike.apache.org/documentation/jpa.html#ExtendedPersistenceContexts
>
>
>
> 2016-01-17 23:44 GMT+01:00 Alex Roytman <ro...@gmail.com>:
>
> > 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
> >
>

Re: Transactional with extended EntityManager is not working?

Posted by Gerhard Petracek <ge...@gmail.com>.
hi alex,

please have a look at [1].

regards,
gerhard

[1]
http://deltaspike.apache.org/documentation/jpa.html#ExtendedPersistenceContexts



2016-01-17 23:44 GMT+01:00 Alex Roytman <ro...@gmail.com>:

> 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
>

Re: Transactional with extended EntityManager is not working?

Posted by "John D. Ament" <jo...@gmail.com>.
Sorry I'm also assuming that you added @Transactional to your jdo entity
manager, and not on other classes.
On Jan 17, 2016 22:13, "John D. Ament" <jo...@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" <ro...@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 <ro...@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 <jo...@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 <ro...@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
>> >> >
>> >>
>> >
>>
>

Re: Transactional with extended EntityManager is not working?

Posted by Alex Roytman <ro...@gmail.com>.
John,

To give you a buildable project I would need to strip all private maven
dependencies from it and all extra code. Would just relevant class files be
useful to you to take a look or you need a buildable/runnable project?

Thanks
alex


On Mon, Jan 18, 2016 at 9:59 PM John D. Ament <jo...@apache.org> wrote:

> Alex,
>
> Now i'm very intrigued (I was previously just intrigued/confused).  Any
> chance you have a sample project that reproduces the issue?
>
> John
>
> On Mon, Jan 18, 2016 at 9:32 PM Alex Roytman <ro...@gmail.com> wrote:
>
> > John,
> >
> > It is weld latest version plus jersey in tomcat 7.
> >
> > It really is weld that's in play here. It creates client proxy for
> injected
> > entity manager and the interface for which proxy is created depend on
> > return type of producer not the declared type of the field being
> injected.
> > So when my producer was returning EntityManager I could not cast it to my
> > JdoEntityManager. As for transactional interceptor it seems to me it
> should
> > recognize any injected interface that extends EntityManager. Or even
> better
> > be configurable to provide transactional semantics to any interface that
> > can expose transaction methods in some way
> >
> >
> > On Mon, Jan 18, 2016, 7:37 PM John D. Ament <jo...@apache.org>
> wrote:
> >
> > > Alex,
> > >
> > > That... doesn't make any sense, though I'm glad you were able to solve
> > it.
> > >
> > > What container are you targetting? The method return type on a producer
> > has
> > > nothing to do with the possible types that it can inject into (though
> > they
> > > generally should be of similar types, you're just providing an extra
> bean
> > > into the context).
> > >
> > > John
> > >
> > > On Sun, Jan 17, 2016 at 10:31 PM Alex Roytman <ro...@gmail.com>
> > wrote:
> > >
> > > > 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" <ro...@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
> > > > > > >> >
> > > > > > >>
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>

Re: Transactional with extended EntityManager is not working?

Posted by "John D. Ament" <jo...@apache.org>.
Alex,

Now i'm very intrigued (I was previously just intrigued/confused).  Any
chance you have a sample project that reproduces the issue?

John

On Mon, Jan 18, 2016 at 9:32 PM Alex Roytman <ro...@gmail.com> wrote:

> John,
>
> It is weld latest version plus jersey in tomcat 7.
>
> It really is weld that's in play here. It creates client proxy for injected
> entity manager and the interface for which proxy is created depend on
> return type of producer not the declared type of the field being injected.
> So when my producer was returning EntityManager I could not cast it to my
> JdoEntityManager. As for transactional interceptor it seems to me it should
> recognize any injected interface that extends EntityManager. Or even better
> be configurable to provide transactional semantics to any interface that
> can expose transaction methods in some way
>
>
> On Mon, Jan 18, 2016, 7:37 PM John D. Ament <jo...@apache.org> wrote:
>
> > Alex,
> >
> > That... doesn't make any sense, though I'm glad you were able to solve
> it.
> >
> > What container are you targetting? The method return type on a producer
> has
> > nothing to do with the possible types that it can inject into (though
> they
> > generally should be of similar types, you're just providing an extra bean
> > into the context).
> >
> > John
> >
> > On Sun, Jan 17, 2016 at 10:31 PM Alex Roytman <ro...@gmail.com>
> wrote:
> >
> > > 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 <jo...@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" <ro...@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 <ro...@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
> > > > > >> >
> > > > > >>
> > > > > >
> > > > >
> > > >
> > >
> >
>

Re: Transactional with extended EntityManager is not working?

Posted by Alex Roytman <ro...@gmail.com>.
John,

It is weld latest version plus jersey in tomcat 7.

It really is weld that's in play here. It creates client proxy for injected
entity manager and the interface for which proxy is created depend on
return type of producer not the declared type of the field being injected.
So when my producer was returning EntityManager I could not cast it to my
JdoEntityManager. As for transactional interceptor it seems to me it should
recognize any injected interface that extends EntityManager. Or even better
be configurable to provide transactional semantics to any interface that
can expose transaction methods in some way


On Mon, Jan 18, 2016, 7:37 PM John D. Ament <jo...@apache.org> wrote:

> Alex,
>
> That... doesn't make any sense, though I'm glad you were able to solve it.
>
> What container are you targetting? The method return type on a producer has
> nothing to do with the possible types that it can inject into (though they
> generally should be of similar types, you're just providing an extra bean
> into the context).
>
> John
>
> On Sun, Jan 17, 2016 at 10:31 PM Alex Roytman <ro...@gmail.com> wrote:
>
> > 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 <jo...@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" <ro...@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 <ro...@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 <ro...@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
> > > > >> >
> > > > >>
> > > > >
> > > >
> > >
> >
>

Re: Transactional with extended EntityManager is not working?

Posted by "John D. Ament" <jo...@apache.org>.
Alex,

That... doesn't make any sense, though I'm glad you were able to solve it.

What container are you targetting? The method return type on a producer has
nothing to do with the possible types that it can inject into (though they
generally should be of similar types, you're just providing an extra bean
into the context).

John

On Sun, Jan 17, 2016 at 10:31 PM Alex Roytman <ro...@gmail.com> wrote:

> 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 <jo...@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" <ro...@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 <ro...@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 <ro...@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
> > > >> >
> > > >>
> > > >
> > >
> >
>

Re: Transactional with extended EntityManager is not working?

Posted by Alex Roytman <ro...@gmail.com>.
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 <jo...@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" <ro...@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 <ro...@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 <jo...@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 <ro...@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
> > >> >
> > >>
> > >
> >
>

Re: Transactional with extended EntityManager is not working?

Posted by "John D. Ament" <jo...@apache.org>.
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" <ro...@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 <ro...@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 <jo...@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 <ro...@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
> >> >
> >>
> >
>

Re: Transactional with extended EntityManager is not working?

Posted by Alex Roytman <ro...@gmail.com>.
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 <ro...@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 <jo...@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 <ro...@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
>> >
>>
>

Re: Transactional with extended EntityManager is not working?

Posted by Alex Roytman <ro...@gmail.com>.
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 <jo...@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 <ro...@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
> >
>

Re: Transactional with extended EntityManager is not working?

Posted by Alex Roytman <ro...@gmail.com>.
Hello John,

Yes I need

public interface JdoEntityManager  extends EntityManager {

}

but if I inject JdoEntityManager   it is not recognized by @Transactionsl

Please see my previous email in response to Gerhard for rationale

Thanks
alex



On Sun, Jan 17, 2016 at 6:12 PM John D. Ament <jo...@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 <ro...@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
> >
>

Re: Transactional with extended EntityManager is not working?

Posted by "John D. Ament" <jo...@apache.org>.
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 <ro...@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
>