[jboss-user] [EJB 3.0] - Transaction drives me crazy

mamato do-not-reply at jboss.com
Sat Jul 18 09:52:14 EDT 2009


Hi,
let me explain my problem.

I've a little sample application with a servlet, calling a stateless session bean on jboss 5.0.1

The method on the session bean just tryes to persist an entity bean into the DB (mySQL)

All that i wanna do is to be able to manage the transaction by myself.
I mean if something happens the transaction has to be committed, else, rolled back.

I've tryed everithing but the results are:
- if I join the transaction the record is written in any case
- if I don't join the record is not written also il I commit the transaction

I've read a lot around and the code is:

@Stateless(name="WebFacadeBean")
@TransactionManagement(TransactionManagementType.BEAN)
public class WebFacadeBean implements WebFacadeBeanRemote, WebFacadeBeanLocal {

	private EntityManager manager;
	
	// BMT idiom
	@Resource public UserTransaction userTransaction;
	@PersistenceUnit public EntityManagerFactory entityManagerFactory;

	public void method() {
		try {
	    	manager = entityManagerFactory.createEntityManager();
	    	userTransaction.begin();

	    	manager.joinTransaction();

			Ricarica ricarica = new Ricarica();
			
			manager.merge(ricarica);
			
                        boolean doTheJob = true
                        if(!doTheJob)
                             throw new Exception("Do rollback");

			manager.flush();
		
			userTransaction.commit();
		
		} catch (Exception e) {
			try {
				userTransaction.rollback();
			} catch (Exception e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
....


PLEASE HELP !!
Thanks a lot.

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

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



More information about the jboss-user mailing list