7 Replies Latest reply on Feb 21, 2015 8:07 AM by uchmannuz

    Wildfly 8.1 with Spring-managed JPA

    pgmjsd

      I've got a Spring/JPA application that I'm trying to deploy into Wildfly 8.1.  I thought that I would stick with the bundled JPA approach for now, and keep Hibernate in the WEB-INF/lib directory of the .war file.   So, I followed the recommendations here:

       

      Spring applications development and migration guide - WildFly 8 - Project Documentation Editor

       

      The issue that keeps cropping up is that, although I've moved my persistence.xml file out of it's standard location (META-INF/persistence.xml has been moved to META-INF/myapp-persistence.xml), WildFly still finds it when the app is being deployed so the deployment fails.   I've also excluded JPA and Hibernate in jboss-deployment-structure.xml.

       

      Any ideas?   Should I just bail and let Wildfly manage the JPA persistence unit?   I guess it wouldn't be that big of a deal to do that, but I was hoping to make these changes more gradually.

       

      Currently the application deploys just fine in Tomcat 7.x.

        • 1. Re: Wildfly 8.1 with Spring-managed JPA
          pgmjsd

          Here's the exception I get:

          2014-11-29 13:40:30,902 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deployment.unit."myapp.war".FIRST_MODULE_USE: org.jboss.msc.service.StartException in service jboss.deployment.unit."myapp.war".FIRST_MODULE_USE: JBAS018733: Failed to process phase FIRST_MODULE_USE of deployment "myapp.war"
                  at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:166) [wildfly-server-8.1.0.Final.jar:8.1.0.Final]
                  at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
                  at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
                  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_60]
                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_60]
                  at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_60]
          Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011426: Could not deploy application packaged persistence provider 'org.hibernate.jpa.HibernatePersistenceProvider'
                  at org.jboss.as.jpa.processor.PersistenceProviderHandler.deploy(PersistenceProviderHandler.java:81)
                  at org.jboss.as.jpa.processor.PersistenceBeginInstallProcessor.deploy(PersistenceBeginInstallProcessor.java:49)
                  at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:159) [wildfly-server-8.1.0.Final.jar:8.1.0.Final]
                  ... 5 more
          Caused by: java.lang.ClassCastException: class org.hibernate.jpa.HibernatePersistenceProvider
                  at java.lang.Class.asSubclass(Class.java:3165) [rt.jar:1.7.0_60]
                  at org.jboss.as.jpa.processor.PersistenceProviderHandler.deploy(PersistenceProviderHandler.java:74)
                  ... 7 more
          

           

          As you can see, the deployment scanner is trying to do something with JPA, and failing.

          • 2. Re: Wildfly 8.1 with Spring-managed JPA
            pgmjsd

            Okay, I've been able to get past this by moving the JPA descriptors out of the META-INF directory.   Simply renaming them, as the documentation suggests (e.g. jpa-persistence.xml) did not work.

             

            I'll comment on the documentation.

            • 3. Re: Wildfly 8.1 with Spring-managed JPA
              smarlow

              If the persistence unit definition, has jboss.as.jpa.managed set to false, the JPA container/subsystem will not deploy the persistence unit.  This doesn't impact injection though (@PersistenceUnit will still lookup the persistence unit).  Not sure if that helps you at all.

              1 of 1 people found this helpful
              • 4. Re: Wildfly 8.1 with Spring-managed JPA
                pgmjsd

                Thanks.   I'll give that a try.   Since I've moved the descriptor, things get a little further.   However, it's not finding my entities now.   The named queries fail to initialize because of that.    Also odd is that the Hibernate logs are showing up in WildFly's server.log file, even though I am trying to use the application bundled log4j2.

                 

                That's probably a classloader issue I'm guessing.   Under Tomcat this all works fine, BTW.

                 

                Maybe it would be better for me to just switch to a container managed persistence unit?

                • 5. Re: Wildfly 8.1 with Spring-managed JPA
                  smarlow

                  Using a container managed persistence unit is the well travelled path and will be easier to deal with.  Others have gone through the extra effort (configuration/code changes) to use Spring, so some are also using Spring managed persistence units (helpful if there are Spring features that you need to use).

                  • 6. Re: Wildfly 8.1 with Spring-managed JPA
                    pgmjsd

                    Okay, the documentation here: Spring applications development and migration guide - WildFly 8 - Project Documentation Editor has a few glitches:

                    • The <persistence-context-ref> example has an incorrect close tag.   It should be </persistence-context-ref-name>
                    • Spring's PersistenceAnnotationBeanPostProcessor wants the EntityManager in a bean with the same name as the persistence unit, but the Spring JpaTransactionManager wants the EntityManagerFactory.    Maybe I should just use JTA?  Anyway, I'm having to declare both in web.xml and applicationContext.xml.   That's kinda weird.
                    • 7. Re: Wildfly 8.1 with Spring-managed JPA
                      uchmannuz

                      Hello Joshua,

                      This may be coming too late. I had similar issues. I did some research and solved the issue. I posted the solution on stackoverflow. Below is the link.

                       

                      How to Deploy a Spring managed JPA application on JBoss 6.3 EAP