users@glassfish.java.net

Re: JTA transactions inside Session beans and JSF

From: <glassfish_at_javadesktop.org>
Date: Mon, 04 Aug 2008 07:49:52 PDT

Hi Quentin,

In order to use the session beans you'll need to acquire an EJB reference for each one.
In the EJB programming model the client never directly calls new() on the bean class.
It's easy to get the EJB reference in a JSF managed bean. Just add an @EJB annotation
to a field whose type is the local business interface of the session bean.

E.g.

@EJB private PersonLocal p;

The reference will be injected automatically in your BusinessBean.

Regarding transactions, the easiest thing would be to add a third facade session bean
within which the other session bean calls are made. By default, session beans have
container-managed transactions. So, the call to the facade session bean will start a
transaction and the subsequent calls it makes will take place within the same transaction.

The alternative to is to explicitly demarcate a transaction within the JSF managed bean
before calling the Person and Address session beans. That's done with a
javax.transaction.UserTransaction object. However, it's a more complicated approach.
[Message sent by forum member 'ksak' (ksak)]

http://forums.java.net/jive/thread.jspa?messageID=291333