geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Darv <dar...@sinnetamby.com>
Subject EJB Transaction inter server propagation
Date Wed, 13 Aug 2014 14:11:54 GMT
I am having some difficulty with transaction propagation between two EJBs on
seperate servers (which I understand can be done based on section 13.2.3 of
the EJB3.1 spec), and I would appreciate if some who might have done this,
could help me.

I am a bit green with EJBs so please excuse me. My initial thought was to
use RemoteInitialContextFactory to initiate the context and then lookup the
remote EJB. While the EJBs communicate ok, unfortunately the transaction
does not propagate, even if the 2 EJB's are on the same server (but
different projects). The @EJB annotation on the remote interface however
does propagate the transaction when on the same machine (diff projects).

The prototype code below is where MyFirstEjbBean saves a customer and then
calls MySecondEjbBean which save another customer on a seperate schema.
MyFirstEjbBean can then blow up to test the rollback. What annotations and
xml definitions are required to enable this to work inter servers? An
example would be greatly appreciated.

@Stateless
public class MyFirstEjbBean implements MyFirstEjb, MyFirstEjbRemote {
	
	@PersistenceContext(name="EJBPrototypesPU")  
	private EntityManager em;
	
	@EJB
	MySecondEjbRemote mySecondEjb;
	
	public void saveCustomers(){  
		Customer customer = new Customer("name1", "address1", "city1");  
		em.persist(customer);  
		
		mySecondEjb.saveCustomer();
		
//		throw new IllegalStateException("Blowing up!");		
	}
}


@Stateless
public class MySecondEjbBean implements MySecondEjb, MySecondEjbRemote {
	
	@PersistenceContext(name="EJBPrototypesPU")  
	private EntityManager em;

	@TransactionAttribute(TransactionAttributeType.MANDATORY) 
	public void saveCustomer() {
		// TODO Auto-generated method stub
		
		Customer cust2 = new Customer("name2", "addr2","city2");
		
		em.persist(cust2);  
	}
}

persistance.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
	<persistence-unit name="EJBPrototypesPU" transaction-type="JTA">
  		<jta-data-source>jdbc/dstestxa</jta-data-source>
  		<non-jta-data-source>jdbc/dstest</non-jta-data-source>
  		<properties>
  			<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)"/>
  			<property name="openjpa.Sequence" value="table(Table=OPENJPASEQ,
Increment=1)"/>
  			<property name="openjpa.Log" value="DefaultLevel=WARN, Runtime=TRACE,
Tool=INFO"/>  		</properties>  		
	</persistence-unit>	

</persistence>

Note: I am using Geronimo 3.0.1 which supports EJB3.1.



--
View this message in context: http://apache-geronimo.328035.n3.nabble.com/EJB-Transaction-inter-server-propagation-tp3988189.html
Sent from the Users mailing list archive at Nabble.com.

Mime
View raw message