WildFly
  1. WildFly
  2. WFLY-2387

CDI injection in entity listeners failing

    Details

    • Similar Issues:
      Show 10 results 

      Description

      When trying to use CDI injection in JPA entity listeners, deployment fails with the following exception:

      16:16:37,448 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 15) MSC000001: Failed to start service jboss.persistenceunit."inject-ear.ear#primary": org.jboss.msc.service.StartException in service jboss.persistenceunit."inject-ear.ear#primary": java.lang.IllegalStateException: JBAS016071: Singleton not set for org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader@4eeb95dc. This means that you are trying to access a weld deployment with a Thread Context ClassLoader that is not associated with the deployment.
      	at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:169)
      	at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117)
      	at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_25]
      	at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:463) [wildfly-security-manager-1.0.0.Beta3.jar:1.0.0.Beta3]
      	at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:178)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_25]
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_25]
      	at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25]
      	at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.1.1.Final.jar:2.1.1.Final]
      Caused by: java.lang.IllegalStateException: JBAS016071: Singleton not set for org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader@4eeb95dc. This means that you are trying to access a weld deployment with a Thread Context ClassLoader that is not associated with the deployment.
      	at org.jboss.as.weld.services.ModuleGroupSingletonProvider$TCCLSingleton.get(ModuleGroupSingletonProvider.java:75)
      	at org.jboss.as.weld.services.ModuleGroupSingletonProvider$TCCLSingleton.get(ModuleGroupSingletonProvider.java:128)
      	at org.jboss.weld.Container.instance(Container.java:65)
      	at org.jboss.weld.manager.BeanManagerImpl.getBeans(BeanManagerImpl.java:563)
      	at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:90)
      	at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:358)
      	at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:369)
      	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.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48)
      	at org.jboss.weld.injection.producer.DefaultInjector.inject(DefaultInjector.java:64)
      	at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:90)
      	at org.hibernate.jpa.event.internal.jpa.BeanManagerListenerFactory$BeanMetaData.<init>(BeanManagerListenerFactory.java:82)
      	at org.hibernate.jpa.event.internal.jpa.BeanManagerListenerFactory$BeanMetaData.<init>(BeanManagerListenerFactory.java:71)
      	at org.hibernate.jpa.event.internal.jpa.BeanManagerListenerFactory.buildListener(BeanManagerListenerFactory.java:57)
      	at org.hibernate.jpa.event.internal.jpa.LegacyCallbackProcessor.resolveCallbacks(LegacyCallbackProcessor.java:168)
      	at org.hibernate.jpa.event.internal.jpa.LegacyCallbackProcessor.processCallbacksForEntity(LegacyCallbackProcessor.java:71)
      	at org.hibernate.jpa.event.spi.JpaIntegrator.integrate(JpaIntegrator.java:150)
      	at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:310)
      	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1837)
      	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:854)
      	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:847)
      	at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:396)
      	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:846)
      	at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
      	at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:151)
      	... 8 more
      

      I've created a small showcase of the problem: https://github.com/papegaaij/listener-injection

        Gliffy Diagrams

          Issue Links

            Activity

            Hide
            Scott Marlow added a comment -

            Cody Lerum, IMO, the workaround would be a patch for the above mentioned HHH-8706 for the Hibernate 4.3/master branches. As far as I know, no one has tried to create a Hibernate patch yet. Someone will eventually get around to working on HHH-8706 but not sure when. Any volunteers?

            No one has mentioned whether other persistence providers are already doing the equivalent of HHH-8706 (registering the entity listener as late as possible). Have you tried EclipseLink or OpenJPA to see if they lazily register the entity listener?

            Show
            Scott Marlow added a comment - Cody Lerum , IMO, the workaround would be a patch for the above mentioned HHH-8706 for the Hibernate 4.3/master branches. As far as I know, no one has tried to create a Hibernate patch yet. Someone will eventually get around to working on HHH-8706 but not sure when. Any volunteers? No one has mentioned whether other persistence providers are already doing the equivalent of HHH-8706 (registering the entity listener as late as possible). Have you tried EclipseLink or OpenJPA to see if they lazily register the entity listener?
            Hide
            Cody Lerum added a comment -

            Scott Marlow I haven't tried other than Hibernate as that's what I'm deployed on (WFLY 8.1) .I just ran into this today trying to do an injection into an EntityListener

            I worked around it using a BeanManager, but was more curious about the long term. Is this already handled in Hibernate 5?

            Show
            Cody Lerum added a comment - Scott Marlow I haven't tried other than Hibernate as that's what I'm deployed on (WFLY 8.1) .I just ran into this today trying to do an injection into an EntityListener I worked around it using a BeanManager, but was more curious about the long term. Is this already handled in Hibernate 5?
            Hide
            Scott Marlow added a comment -

            [Cody Lerum, until someone tries to patch HHH-8706, the long term is unknown.

            Show
            Scott Marlow added a comment - [ Cody Lerum , until someone tries to patch HHH-8706, the long term is unknown.
            Hide
            Dirk Franssen added a comment -

            Just for info: injection in an entity listener on Glassfish 4.1 doesn't work either. (@Inject seems to be ignored and the field stays null, resulting in nullpointer exceptions)

            Currently I also use the BeanManager workaround on Wildfly 8.1.0.Final. This BeanManager can be injected though, so no need for a jndi lookup.

            MyEntityListener.java

            ...
            @Inject
            BeanManager beanManager; //Workaround WFLY-2387
            ...
             
            protected String getPrincipalName() {
                    //Workaround WFLY-2387
                    Set beans = beanManager.getBeans(Principal.class);
                    Bean bean = (Bean) beans.iterator().next();
                    CreationalContext ctx = beanManager.createCreationalContext(bean);
                    Principal principal =  (Principal) beanManager.getReference(bean, Principal.class, ctx);
                    
                    return principal.getName();
            }
            

            Show
            Dirk Franssen added a comment - Just for info: injection in an entity listener on Glassfish 4.1 doesn't work either. (@Inject seems to be ignored and the field stays null, resulting in nullpointer exceptions) Currently I also use the BeanManager workaround on Wildfly 8.1.0.Final. This BeanManager can be injected though, so no need for a jndi lookup. MyEntityListener.java ... @Inject BeanManager beanManager; //Workaround WFLY-2387 ...   protected String getPrincipalName() { //Workaround WFLY-2387 Set beans = beanManager.getBeans(Principal.class); Bean bean = (Bean) beans.iterator().next(); CreationalContext ctx = beanManager.createCreationalContext(bean); Principal principal = (Principal) beanManager.getReference(bean, Principal.class, ctx); return principal.getName(); }
            Hide
            Scott Marlow added a comment -

            Is the best test case still at https://issues.jboss.org/browse/WFLY-2387?focusedCommentId=12826416&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-12826416? How does that fail? If there is an updated failure (other than "Singleton not set for org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader@5bedfb57.") could you please attach it.

            The current attachment reflects an already fixed "Singleton not set for " error.

            Show
            Scott Marlow added a comment - Is the best test case still at https://issues.jboss.org/browse/WFLY-2387?focusedCommentId=12826416&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-12826416 ? How does that fail? If there is an updated failure (other than "Singleton not set for org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader@5bedfb57.") could you please attach it. The current attachment reflects an already fixed "Singleton not set for " error.

              People

              • Assignee:
                Scott Marlow
                Reporter:
                Emond Papegaaij
              • Votes:
                13 Vote for this issue
                Watchers:
                22 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Development