i am creating a web service using 3rd party wsdl that helps me in getting a kind of notification. now i have to save that notification in DB and perform several other operations related to DataBase. in My persistence.xml there are two persistence units as following:
<persistence-unit name="PU1" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/vsDS</jta-data-source>
<class>com.Response</class>
<class>com.Request</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="eclipselink.logging.level" value="INFO"/>
</properties>
</persistence-unit>
<persistence-unit name="PU2" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/vdDS</jta-data-source>
<class>com.LogRequest</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="eclipselink.logging.level" value="INFO"/>
</properties>
</persistence-unit>
till yet i have made a class named Service.java that have all functions i need to perform on DB as following:
public class Service {
private static Logger logger = Logger.getLogger(Service.class);
private EntityManagerFactory PU1;
private EntityManagerFactory PU2;
public Service(){
System.out.println("in service's constructer");
PU1=Persistence.createEntityManagerFactory("PU1");
PU2=Persistence.createEntityManagerFactory("PU2");
}
public void logSubRequest(String msg){
EntityManager em= PU1.createEntityManager();
try{
em.getTransaction().begin();
Request req=new Request();
req.setMessage(msg);
req.setStatus("Y");
em.persist(req);
em.getTransaction().commit();
}catch(Exception e){
logger.error("In logSubRequest="+e.getMessage());
e.printStackTrace();
}finally{
if(em.isOpen()){
em.close();
}
}
}
// there are several other methods of such kind that either persist entities or executeUpdate
}
My Question is: Am i going with standard approach to implement JPA with webservice or should i go with some other technology/method. kindly suggest and guide if i am doing any thing out of standard.