1

I would like to execute some logic before Persistence Unit is loaded in Wildfly 8.0. I have a structure like this:

  • xxx.ear
    • before-persistence-bean.jar
    • beans.jar
    • xxx.war

beans.jar contains entity beans with persistence.XML and session beans

before-persistence-bean.jar contains one class:

@Startup
@Singleton
public class BeforePersistenceServiceBean {

    @PostConstruct
    public void performOperations() {...}

}

In application.xml I have:

<initialize-in-order>true</initialize-in-order>
<module>
    <ejb>before-persistence-bean.jar</ejb>
</module>
<module>
    <ejb>beans.jar</ejb>
</module>
<module>
    <web>
        <web-uri>xxx.war</web-uri>
        <context-root>/xxx</context-root>
    </web>
</module>

Now, after starting Wildfly I get error that:

service jboss.persistenceunit."xxx.ear/beans.jar#pu_name" (missing) dependents: 
[service jboss.deployment.subunit."xxx.ear"."before-persistence
bean.jar".component.BeforePersistenceServiceBean.START] 

But BeforePersistenceServiceBean doesn't have dependency on Persistence Unit, what is going on here ?

---EDIT---

After failing to deploy this bean before persistence kicks off, I have used solution similar to described in CDI Extension for Flyway (i.e. using Hibernate Integrator API)

Community
  • 1
  • 1
mnx
  • 11
  • 2
  • 4
  • Are you able to provide snippet of the code? It will help to debug it – Krzysztof Miksa Apr 15 '14 at 16:24
  • The method performOperations is actually empty (for now), just testing possible solution to execute something before persistence unit is deployed – mnx Apr 15 '14 at 16:46

1 Answers1

1

Add a jboss-deployment-structure.xml to the META-INF directory if your EAR to indicate you want the subdeployments isolated.

I would imagine the contents would look something like

<subsystem xmlns="urn:jboss:domain:ee:1.0" >            
  <ear-subdeployments-isolated>false</ear-subdeployments-isolated>
  <sub-deployment name="xxx.war">
    <dependencies>
      <module name="deployment.xxx.ear.beans.jar" />
    </dependencies>
  </sub-deployment>
</subsystem>
James R. Perkins
  • 16,800
  • 44
  • 60
  • It haven't helped, whether ear-subdeployments-isolated is set to true or false - same problem (service jboss.persistenceunit."xxx.ear/beans.jar#pu_name" (missing)) – mnx Apr 17 '14 at 06:49
  • I would assume the answer is yes, but does your beans.jar use JPA? – James R. Perkins Apr 17 '14 at 16:05
  • yes, as I said, beans.jar contains entity beans with JPA persistence.xml, but before-persistence-bean.jar doesn't have dependency neither on beans.jar nor JPA – mnx Apr 18 '14 at 09:13
  • No, nothing more in error message, just dependecy missing... I've found antoher solution as described in EDIT section of the question, thanks – mnx Apr 23 '14 at 07:34