[jboss-user] [O'Reilly JBoss 3.0/4.0 Workbook] - Transaction over multiple entitity beans

literadix do-not-reply at jboss.com
Tue Jan 16 00:18:53 EST 2007

Hi all !

I have read also the Oreilly's book, but can not figure out how construct the following:

I have multiple Entities (Entity1, Entity2, ..., EntityN) and have put on top of each entity a session bean (Entity1Dao, Entity2Dao, ..., EntityNDao). What I want to do is to hadle an update of entity1, entity2, entityn within one single transaction. 

Any exception during entity management should mark the just running transaction for rollback, so when an exception occured within Entity2Dao no data from Entity1 should persist. After the command flow has end, I would like to commit all changes (transaction commit).

Is there any public example or some nice lad who can give me any source code how to manage this? If possible, I would like not to use stateful beans and. The base code for my entity DAOs is like this:

  | public abstract class GenericDaoImpl<T extends GenericDatabaseObject, PK extends Serializable> implements GenericDao<T, PK> {
  | 	/** EntityManager */
  | 	@PersistenceContext(type=PersistenceContextType.TRANSACTION)
  | 	EntityManager manager;
  | 	@TransactionAttribute(TransactionAttributeType.REQUIRED )
  | 	public void save(T instance) {
  | 		System.out.println(manager);
  | 		manager.persist(instance);
  | 	}
  | 	@TransactionAttribute(TransactionAttributeType.REQUIRED )
  | 	public void delete(T persistentObject) {
  | 		manager.remove(persistentObject);
  | 	}

and the sub class for a specific session bean:

  | @Stateless(name = "AddressDao")
  | @Remote(AddressDao.class)
  | @Local(AddressDao.class)
  | public class AddressDaoImpl extends GenericDaoImpl<Address, Long> implements AddressDao {
  | }

I am using the latest JBOSS 4.0.5 and EJB3R9 and PersistenceContextType.TRANSACTION for the EntityManager. 

Thank you very much,

Maciej A. Bednarz

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4002120#4002120

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4002120

More information about the jboss-user mailing list