5 Replies Latest reply on Mar 12, 2014 10:05 PM by noamichael

    TransactionRequiredException with JPA IDM & Glassfish

    jluv

      Hi,

       

      I'm setting up a proof of concept for IDM JPA with PicketLink 2.5.3-SNAPSHOT on Glassfish 4.  I've followed the picketlink-authorization-idm-jpa quickstart  and I have a MySQL database all set up.  I worked through a few mapping problems with EclipseLink 2.5.1 by adding an orm.xml and I'm so close to making it all work.  Within my IDMInitializer, EclipseLink is throwing a TransactionRequiredException when "IdentityManager identityManager = partitionManager.createIdentityManager();" is called, trying to create a default partition.

       

      I've tried downgrading to PicketLink 2.5.2.Final and the result is the same.  I've also tried providing my own ContextInitialzer as described at Chapter 7. Identity Management - Working with JPA

      but this doesn't fix the problem either.  I've also tried @TransactionAttribute(TransactionAttributeType.REQUIRED), @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) and even doing Bean Managed Transactions with an injected UserTransaction.  The result is always a TransactionRequiredException.

       

      I'd really appreciate some help on this.  My stacktrace is below.

       

      Thanks!

      John

       

       

      SEVERE: Exception while loading the app : javax.ejb.CreateException: Initialization failed for Singleton IDMInitializer

      javax.ejb.CreateException: Initialization failed for Singleton IDMInitializer

        at com.sun.ejb.containers.AbstractSingletonContainer.createSingletonEJB(AbstractSingletonContainer.java:483)

        at com.sun.ejb.containers.AbstractSingletonContainer.access$000(AbstractSingletonContainer.java:81)

        at com.sun.ejb.containers.AbstractSingletonContainer$SingletonContextFactory.create(AbstractSingletonContainer.java:654)

        at com.sun.ejb.containers.AbstractSingletonContainer.instantiateSingletonInstance(AbstractSingletonContainer.java:396)

        at org.glassfish.ejb.startup.SingletonLifeCycleManager.initializeSingleton(SingletonLifeCycleManager.java:219)

        at org.glassfish.ejb.startup.SingletonLifeCycleManager.initializeSingleton(SingletonLifeCycleManager.java:180)

        at org.glassfish.ejb.startup.SingletonLifeCycleManager.doStartup(SingletonLifeCycleManager.java:158)

        at org.glassfish.ejb.startup.EjbApplication.start(EjbApplication.java:166)

        at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)

        at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:291)

        at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:352)

        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:497)

        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)

        at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)

        at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:527)

        at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:523)

        at java.security.AccessController.doPrivileged(Native Method)

        at javax.security.auth.Subject.doAs(Subject.java:356)

        at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:522)

        at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:546)

        at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1423)

        at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1500(CommandRunnerImpl.java:108)

        at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1762)

        at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1674)

        at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534)

        at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224)

        at org.glassfish.grizzly.http.server.StaticHttpHandler.service(StaticHttpHandler.java:297)

        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:246)

        at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)

        at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)

        at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)

        at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)

        at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)

        at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)

        at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)

        at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)

        at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)

        at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)

        at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)

        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)

        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)

        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)

        at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)

        at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)

        at java.lang.Thread.run(Thread.java:724)

      Caused by: org.picketlink.idm.IdentityManagementException: PLIDM000401: Could not create partition [59f360a8-0abd-41a7-b03a-e59b8a30d953] using configuration [default].

        at org.picketlink.idm.internal.DefaultPartitionManager.add(DefaultPartitionManager.java:367)

        at org.picketlink.idm.internal.DefaultPartitionManager.add(DefaultPartitionManager.java:334)

        at org.picketlink.producer.IdentityManagerProducer.createDefaultPartition(IdentityManagerProducer.java:201)

        at org.picketlink.producer.IdentityManagerProducer.createEmbeddedPartitionManager(IdentityManagerProducer.java:213)

        at org.picketlink.producer.IdentityManagerProducer.init(IdentityManagerProducer.java:105)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:606)

        at org.jboss.weld.injection.MethodInjectionPoint.invokeWithSpecialValue(MethodInjectionPoint.java:72)

        at org.jboss.weld.injection.MethodInjectionPoint.invoke(MethodInjectionPoint.java:66)

        at org.jboss.weld.util.Beans.callInitializers(Beans.java:401)

        at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:389)

        at org.jboss.weld.injection.producer.DefaultInjector.inject(DefaultInjector.java:72)

        at org.jboss.weld.injection.producer.ResourceInjector.inject(ResourceInjector.java:60)

        at org.jboss.weld.injection.producer.DefaultInjector$1.proceed(DefaultInjector.java:66)

        at org.glassfish.weld.services.InjectionServicesImpl.aroundInject(InjectionServicesImpl.java:142)

        at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:46)

        at org.jboss.weld.injection.producer.DefaultInjector.inject(DefaultInjector.java:64)

        at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:91)

        at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:158)

        at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:103)

        at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:742)

        at org.jboss.weld.injection.producer.AbstractMemberProducer.getReceiver(AbstractMemberProducer.java:110)

        at org.jboss.weld.injection.producer.AbstractMemberProducer.produce(AbstractMemberProducer.java:129)

        at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:189)

        at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:69)

        at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:742)

        at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:798)

        at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:92)

        at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:376)

        at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:388)

        at org.jboss.weld.injection.producer.DefaultInjector.inject(DefaultInjector.java:72)

        at org.jboss.weld.injection.producer.DefaultInjector$1.proceed(DefaultInjector.java:66)

        at org.glassfish.weld.services.InjectionServicesImpl.aroundInject(InjectionServicesImpl.java:142)

        at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:46)

        at org.jboss.weld.injection.producer.DefaultInjector.inject(DefaultInjector.java:64)

        at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:91)

        at org.glassfish.weld.services.JCDIServiceImpl.injectEJBInstance(JCDIServiceImpl.java:257)

        at com.sun.ejb.containers.BaseContainer.injectEjbInstance(BaseContainer.java:1683)

        at com.sun.ejb.containers.AbstractSingletonContainer.createSingletonEJB(AbstractSingletonContainer.java:443)

        ... 44 more

      Caused by: javax.persistence.TransactionRequiredException

        at com.sun.enterprise.container.common.impl.EntityManagerWrapper.doTxRequiredCheck(EntityManagerWrapper.java:161)

        at com.sun.enterprise.container.common.impl.EntityManagerWrapper.doTransactionScopedTxCheck(EntityManagerWrapper.java:151)

        at com.sun.enterprise.container.common.impl.EntityManagerWrapper.persist(EntityManagerWrapper.java:281)

        at org.picketlink.idm.jpa.internal.mappers.EntityMapper.persist(EntityMapper.java:113)

        at org.picketlink.idm.jpa.internal.JPAIdentityStore.addAttributedType(JPAIdentityStore.java:143)

        at org.picketlink.idm.internal.AbstractIdentityStore.add(AbstractIdentityStore.java:89)

        at org.picketlink.idm.jpa.internal.JPAIdentityStore.add(JPAIdentityStore.java:231)

        at org.picketlink.idm.internal.DefaultPartitionManager.add(DefaultPartitionManager.java:357)

        ... 84 more

        • 1. Re: TransactionRequiredException with JPA IDM & Glassfish
          fer.marino

          I'm having a similar problem. I'm running the jpa idm example on a jboss as, and when I try to modify a user with this:

          IdentityManager im = partitionManager.createIdentityManager();

          im.update(editUser);

           

          the update fail due to a transaction required error.

           

          I inject the partition manager. I also tried to inject directly the identity manager but I got the same error (Could not update AttributedType due to transaction required exception).

          • 2. Re: TransactionRequiredException with JPA IDM & Glassfish
            pcraveiro

            Hi,

             

            I've noticed a similar behavior with TomEE. The problem is that PicketLink creates the default partition (if it does not exists) during the startup, so we need a transaction to get things done.

             

            When using JBoss EAP/WildFly, a transaction is always active during the startup. Specially because you're using a EJB to initialize your stores. But this is not the case for TomEE and probably GlassFish.

             

            I'm investigating this issue to see if we can support all those containers without major changes. Opened a JIRA to track this:

             

            [PLINK-332] PicketLink fails to bootstrap due to TransactionRequiredException on TomEE and GlassFish - JBoss Issue Track…

             

            Regards.

            • 3. Re: Re: TransactionRequiredException with JPA IDM & Glassfish
              jluv

              I've ensured there's an active transaction in the @PostConstruct method invoked in the EJB startup bean, using several different strategies.  It seams that org.picketlink.idm.jpa.internal.mappers.EntityMapper is not using the active transaction, probably because it's not an EJB.

               

              I wonder if org.picketlink.idm.jpa.internal.mappers.EntityMapper.persist were modified to get a transaction reference from the entityManager and start a transaction, if it might work correctly in all environements.  Maybe something like:

              EntityTransaction tx = null;

              try {

                  tx = entityManager.getTransaction();

                  if (tx != null) {

                      tx.begin();

                      entityManager.persist(entity);

                      tx.commit();

                  }

              } catch (Exception e) {

                  if ( tx != null && tx.isActive() ) tx.rollback();

                  throw e;

              }

              • 4. Re: TransactionRequiredException with JPA IDM & Glassfish
                pcraveiro

                Not sure if this works for all environments. Specially when using JTA transactions where you need to use the UserTransaction instead.

                 

                I think we've provided a clean solution for this, can you please take a look at [PLINK-332] ?

                 

                Best regards.

                • 5. Re: TransactionRequiredException with JPA IDM & Glassfish
                  noamichael

                  Unfortunately, this does not work using JTA/NetBeans/Glassfish 4. With the partition initializer class added to my project, I get an error stating that the transaction is active in another thread. Without the partition manager, I get an error stating that I am performing an operation on a closed entity manager factory. Any advice on where to go from here?