1 2 Previous Next 20 Replies Latest reply on Jan 3, 2010 3:12 PM by kva Go to original post
      • 15. Re: Ambiguous resolution
        kva

        If I inject the UserTransaction via @Inject nothing happens. Printing out the transaction gives Transaction: unknown


        If I inject the UserTransaction via @Resource I get NameNotFoundException with message be.sample.WidgetCreator not bound.


        Should deploy as an ear probably, or try glassfish.

        • 16. Re: Ambiguous resolution
          william.drai

          This should work :


             @Inject @MyDB private EntityManager db;
             @Resource private UserTransaction ut;
          
             ...
          
             ut.begin();
             db.joinTransaction();
             db.persist(myEntity);
             db.flush();
             ut.commit();
          



          Not sure that flush is mandatory.

          • 17. Re: Ambiguous resolution
            william.drai

            Sorry @Resource should be :


            @Resource(mappedName="java:comp/UserTransaction") 
            private UserTransaction ut;
            



            Don't know why the mappedName is necessary, but it works in both JBoss 6 and GF 3.

            • 18. Re: Ambiguous resolution
              gavin.king

              According to the spec (3.6) @Inject UserTransaction should work. If it doesn't, that's a bug.

              • 19. Re: Ambiguous resolution
                william.drai

                Right, this works perfectly (in JB6 at least) :


                  @Inject @MyDB private EntityManager db;
                  @Inject private UserTransaction ut;
                
                  ...
                
                  ut.begin();
                  db.joinTransaction();
                  db.persist(myEntity);
                  db.flush();
                  ut.commit();
                


                • 20. Re: Ambiguous resolution
                  kva

                  Yes, this works. Thanks.

                  1 2 Previous Next