[jboss-user] [JBoss Seam] - Re: Problem: Custom validate methods in EJBs crash

bfo81 do-not-reply at jboss.com
Fri Sep 8 15:41:48 EDT 2006

"gavin.king at jboss.com" wrote : There is one problem with performing validation during the action phase: if you are using an extended persistence context, you would prefer to do validation before applying values onto the model object. But by the time we get to the action method, the values have already been applied. It is then difficult to roll back the change to prevent them being written to the database.
  | However, there is a solution: if you use an extended persistence context with manual flushing, you are fine. There is better support for this in CVS.
Here's another way, which works already now without having to wait for Seam 1.1 or using the CVS version;).

  | import javax.ejb.SessionContext;
  | @Resource
  | SessionContext ejbCtx;
  | public String actionMethod() {
  | ...
  |     if (validationFailed)
  |         ejbCtx.setRollbackOnly();
  | ...
  | }

By the way: To prevent the Extended Persistence Context from auto-flushing where you maybe do not expect it, annotate your class with @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) so that no storing will be performed. And to make your save-method work again, annotate it with @TransactionAttribute(TransactionAttributeType.REQUIRED) 

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

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

More information about the jboss-user mailing list