users@glassfish.java.net

RE: JTA transactions inside Session beans and JSF

From: Alex Sherwin <alex.sherwin_at_acadiasoft.com>
Date: Mon, 4 Aug 2008 10:02:57 -0400

A solution for using JTA in my JSF applications (doesn't matter if it's Core
JSF, ICEFaces and Woodstock, etc), is to use Phase Listeners to control a
JTA transcation to wrap an entire Request scope lifecycle.

Basically, I create a phase listener for the first phase and begin the JTA
transaction, and if at any time an explicit commit or rollback (end Tx) is
required, the business code inside the request/session beans do that, always
starting a new Tx afterwards for the rest of the code, and finally a phase
listener listens for the end of the final phase and always ends the current
Tx.

This may or not be helpful in your situation, but it's a pretty easy thing
to try out; implementing a phase listener is pretty trivial... just do a
quick Google search.


Alex Sherwin
alex.sherwin_at_acadiasoft.com

-----Original Message-----
From: quintin_at_skywalk.co.za [mailto:quintin_at_skywalk.co.za] On Behalf Of Q
Beukes
Sent: Saturday, August 02, 2008 11:20 AM
To: users
Subject: JTA transactions inside Session beans and JSF

Hey,

I'm using Glassfish 2, with Toplink JTA and JTA. No extra libraries,
just a pure Netbeans 6.1 and Glassfish installation, then start a
JavaEE app with a WAR/JSF and EJB jar.

Now, I have a bunch of entities inside the EJB, and then use Session
beans to work with them. Inside the session beans I have
@PersistenceContext EntityManager injections to work with the
entities.

Then I have a RequestScopeBean called BusinessBean inside my JSF.

I use this to again work with the Session beans. Methods like for
example "Create Person" which would call the person facade(session
bean) to create the person entities and persist them, and there after
the businessBean will again call a separate session bean called
"create address" for each of the person's addresses.

Here is a depiction:
BusinessBean in War (public class BusinessBean extends AbstractRequestBean)
PersonBean is a session bean
AddressBean is a session bean
Person is an entity
Address is an entity

Now.
Inside BusinessBean I do:
Person p = new Person()
personBean.create(p);

Address a1 = new Address();
addressBean.create(a1);
Address a2 = new Address();
addressBean.create(a2);

Will all this be wrapped in a single transaction? Or do I need to
create a 3rd session bean and wrap the person/addresses creation
inside of?

This app will ONLY be hosted on glassfish.

-- 
Quintin Beukes
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
For additional commands, e-mail: users-help_at_glassfish.dev.java.net