JPA Persistence Unit Processing Conflict When Using Spring with JBoss EAP 5 or JBoss EAP 6

Solution Verified - Updated -

Issue

  • A JPA persistence unit is processed twice, once by JBoss and once by Spring.
  • When using JPA configured using Spring an exception is encountered indicating a unit is not properly mapped or already has been processed.  For example,
      org.hibernate.hql.ast.QuerySyntaxException:
        DropMaster is not mapped [from DropMaster as dm WHERE DROP_MONTH
        =:DROP_MONTH ORDER BY ITEM_MASTER_TYPE, ITEM_MASTER] 
                at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181) 
                at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110) 
                at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:94) 
                at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:316       ...

or

15:00:44,616 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-12) MSC000001: Failed to start service jboss.deployment.unit."example.war".INSTALL: org.jboss.msc.service.StartException
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:123) [jboss-as-server-7.1.3.Final-redhat-4.jar:7.1.3.Final-redhat-4]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA-redhat-2.jar:1.0.2.GA-redhat-2]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA-redhat-2.jar:1.0.2.GA-redhat-2]
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_38]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_38]
    at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_38]
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011446: Failed to add persistence unit service for pu
    at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.deployPersistenceUnit(PersistenceUnitDeploymentProcessor.java:388)
    at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.addPuService(PersistenceUnitDeploymentProcessor.java:260)
    at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.handleWarDeployment(PersistenceUnitDeploymentProcessor.java:196)
    at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.deploy(PersistenceUnitDeploymentProcessor.java:120)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:116) [jboss-as-server-7.1.3.Final-redhat-4.jar:7.1.3.Final-redhat-4]
    ... 5 more
Caused by: org.jboss.msc.service.DuplicateServiceException: Service jboss.persistenceunit."example.war#pu" is already registered
    at org.jboss.msc.service.ServiceRegistrationImpl.setInstance(ServiceRegistrationImpl.java:154) [jboss-msc-1.0.2.GA-redhat-2.jar:1.0.2.GA-redhat-2]
    at org.jboss.msc.service.ServiceControllerImpl.startInstallation(ServiceControllerImpl.java:227) [jboss-msc-1.0.2.GA-redhat-2.jar:1.0.2.GA-redhat-2]
    at org.jboss.msc.service.ServiceContainerImpl.install(ServiceContainerImpl.java:560) [jboss-msc-1.0.2.GA-redhat-2.jar:1.0.2.GA-redhat-2]
    at org.jboss.msc.service.ServiceTargetImpl.install(ServiceTargetImpl.java:201) [jboss-msc-1.0.2.GA-redhat-2.jar:1.0.2.GA-redhat-2]
    at org.jboss.msc.service.ServiceControllerImpl$ChildServiceTarget.install(ServiceControllerImpl.java:2228) [jboss-msc-1.0.2.GA-redhat-2.jar:1.0.2.GA-redhat-2]
    at org.jboss.msc.service.ServiceTargetImpl.install(ServiceTargetImpl.java:201) [jboss-msc-1.0.2.GA-redhat-2.jar:1.0.2.GA-redhat-2]
    at org.jboss.msc.service.ServiceControllerImpl$ChildServiceTarget.install(ServiceControllerImpl.java:2228) [jboss-msc-1.0.2.GA-redhat-2.jar:1.0.2.GA-redhat-2]
    at org.jboss.msc.service.ServiceBuilderImpl.install(ServiceBuilderImpl.java:307) [jboss-msc-1.0.2.GA-redhat-2.jar:1.0.2.GA-redhat-2]
    at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.deployPersistenceUnit(PersistenceUnitDeploymentProcessor.java:382)
    ... 9 more

Environment

  • JBoss Enterprise Application Platform (EAP) 5.x
  • JBoss Enterprise Application Platform (EAP) 6.x
  • Spring 2.5.6
  • Spring 3

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content