I've got a simple storefront app that has a few stateless EJBs that act as DAO
objects, basically. The app also has a single stateful bean which acts as a
session for the shopping cart, it's called ShoppingCartBean.
I've got it all working just fine but I'm not happy w/ the final checkout
action where all order (entities) data is persisted and the SFSB is terminated
w/ @Remove.
I want to make it transactional but I'm unclear how I should do this, really.
I'm using CMT entirely, no BMT in any of this.
Each of the stateless beans declares an EntityManager and the methods there in
use it to query/persist data...really straight-forward stuff.
Now, if I take my SFSB and declare an EntityManager in it...could I make the
methods I call from the injected stateless beans transactional?
Here's an example of what I'm imagining:
| @Stateful
| //@Local(ShoppingCart.class)
| public class ShoppingCartBean
| implements Serializable, ShoppingCartLocal, ShoppingCartRemote
| {
| @PersistenceContext
| private EntityManager em;
| private Order order;
| private Customer customer;
| @EJB Authenticate authBean;
| @EJB Orders orderBean;
|
| public void completeOrder()
| {
| //begin transaction
| this.em.getTransaction().begin();
|
| //get Order in session
| Order order = this.getOrder();
|
| //Customer/User in session
| Customer customer = order.getCustomer();
| User user = customer.getUser();
|
| //Address entities
| Address billing = this.getBillingAddress();
| Address shipping = this.getShippingAddress();
|
| //persist User
| this.authBean.saveUser(user);
|
| //persist Customer
| this.orderBean.saveCustomer(customer);
|
| //commit transaction
| this.em.getTransaction().commit();
| }
| }
|
Is this the proper way to go about this? What are the ramifications for
injecting the other EJBs and the EntityManager in a stateful bean?
All advice is greatly appreciated, thank you!
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3943924#3943924
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3943924
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user