ESB + JPA: possible?
skyfer Mar 3, 2009 9:06 AMHello,
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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"> <persistence-unit name="pu-appMailIntegration"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/appMailMessageDataSource</jta-data-source> </persistence-unit>
My ESB is defined as follows in jboss-esb.xml:
... <services> <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."> <listeners> <scheduled-listener name="SendMailMessageScheduleListener" event-processor="esb.composer.schedule.SimpleScheduledEventMessageComposer" scheduleidref="esb.mail.SendMailMessageTrigger" /> </listeners> <actions mep="OneWay"> <action class="esb.mail.service.GetMailMessageServiceJPA" name="getNewMails" process="getNewMails" /> </actions> </service> ...
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 .lookup("java:comp/env/persistence/appMailIntegration"); ... } catch (NamingException e) { //logger.error(e.getStackTrace()); e.printStackTrace();
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:
META-INF/
deployment.xml
jboss-esb.xml
MANIFEST.MF
dependency1.jar
dependency2.jar
appMailIntegration.jar
jbm-queue-service.xml
appMailIntegration.jar looks like this:
The directory structure containing the class files
META-INF/
MANIFEST.MF
persistence.xml
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.