2 Replies Latest reply on Sep 10, 2010 8:43 AM by Michael Burman

    ESB + JPA: possible?

    Morten Franck Newbie


      I am trying to create an ESB project that uses JPA entities and a JPA EntityManager but I am experiencing some problems. I am using version 4.3.0.GA_SOA of the server.

      When I deploy the ESB file I cannot see any log messages about any entities being loaded so I assume that the persistence unit is not being loaded properly and when my service is invoked I just see the following line in the server.log:

      ERROR [GetMailMessageServiceJPA] [Ljava.lang.StackTraceElement;@450ebf

      which is not really of any use to me.

      My persistence.xml looks like this:

      <?xml version="1.0" encoding="UTF-8" ?>
      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
       xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
       <persistence-unit name="pu-appMailIntegration">

      My ESB is defined as follows in jboss-esb.xml:

       <service category="esb.mail.service" name="GetNewMailMessages"
       description="Get new mails from the MAIL_MESSAGES table and for each of these, invoke the SendMailMessage service.">
       <scheduled-listener name="SendMailMessageScheduleListener"
       scheduleidref="esb.mail.SendMailMessageTrigger" />
       <actions mep="OneWay">
       <action class="esb.mail.service.GetMailMessageServiceJPA"
       name="getNewMails" process="getNewMails" />

      And the GetMailMessageServiceJPA Java class looks like this:

      @PersistenceContext(unitName = "pu-appMailIntegration", name = "persistence/appMailIntegration")
      public class GetMailMessageServiceJPA extends AbstractActionLifecycle {
       private EntityManager entityManager;
       public Message getNewMails(Message message) {
       try {
       InitialContext ic = new InitialContext();
       entityManager = (EntityManager) ic
       } catch (NamingException e) {

      I have also tried directly injecting the EntityManager but with a similar unsuccessful result.

      My project also has a number of dependencies so the ESB file generated by my ant target, appMailIntegration.esb, looks like this:




      appMailIntegration.jar looks like this:

      The directory structure containing the class files


      The reason for creating a seperate jar file containing the persistence.xml is that when the persistence.xml was in the ESB file's META-INF directory, I got errors about the persistence unit already being created (it looked like the server was trying to load persistence.xml for each dependency.jar in the ESB file).

      My questions are:

      1. Is it at all possible to use JPA within an ESB project?
      2. If so, are my problems due to packaging problems? what should the directory structure of my ESB file be?

      I will continue debugging, hoping that you guys have some clever input to help me along.

        • 1. Re: ESB + JPA: possible?
          Morten Franck Newbie

          Update: I circumvented the problem by accessing the JPA entities and entity manager from a stateless session bean which I am then calling from my ESB action. It is therefore still unknown if it's possible to access JPA from ESB.

          • 2. Re: ESB + JPA: possible?
            Michael Burman Newbie

            I'm bringing this up again, since this seems kinda ridiculous. What's the proper way of accessing JPA with the JBoss ESB? The above writer says that he is using EJB's to access them. Fine, but it won't work with Hibernate if it's creating proxy classes. Consider this (ExpressionRuleService is EJB 3.0, which uses @PersistenceContext and creates Query with Hibernate as provider to the database, using JPA annotations):



            InitialContext ctx = new InitialContext();
            ExpressionRuleService ruleService = (ExpressionRuleService) ctx.lookup("ExpressionRuleServiceBean/remote");
            List<Properties> properties = ruleService.getProperties();


            System.out.println("Properties size: " + properties.size()); // Gives us 3


            for(Properties property : properties) {

              if(property == null) { System.out.println("Properties is null, proxy isn't copied"); } // this is true





            How to get the actual response, ever? With Proxied implementations, one can't access JPA's when creating Actions with the ESB. What kind of software wouldn't use database access?


            What's the propert way to access JPA entities? It seems ESB-archive removes the possibility of using any Java EE features, like EJB injections.