Hi,

You can achieve this one of two ways:

1) Throw a system exception from your method (not an application
   exception as that will not cause a rollback). See section 14.6 
   (page 433 in my edition)
2) Use context.setRollbackOnly(). See last few paragraphs of
   section 14.5 (also page 433 in my edition)

Dan.

-- 
Danny Yates
 


-----Original Message-----
From: Joseph Barillari [mailto:[EMAIL PROTECTED] 
Sent: 14 July 2003 08:50
To: jboss-user
Subject: [JBoss-user] Rollback with side-effects, but /without/ a
UserTransaction


Hi.

I've read (namely in the O'Reilly /Enterprise Java Beans/ book, 3rd
ed.), that:

       ...it is strongly recommended that you do not attempt to manage
       transactions explicitly. Through transaction attributes,
       Enterprise JavaBeans provides a comprehensive and simple
       mechanism for delimiting transactions at the method level and
       propagating transactions automatically. Only developers with a
       thorough understanding of transactional systems should attempt
       to use JTA with EJB. (Chap 14.5)

Consequently, I'm curious if it is possible to write the following
code without using a UserTransaction (e.g., using only transaction
attributes). 

I have an entity bean, Foo. I would like to write an interface method
of Foo, update(). update() that adjusts some of Foo's fields, then
calls an internal validation method, validate(), that checks the
validity of those new field values. validate() returns null on
success, and a string explaining any failures if it fails.

If validate() succeeds, I'd like to commit the changes to Foo. If
validate() fails, I'd like to roll back the changes, and return the
error message to the caller.

In pseudo-Java, 

public String update(int val1, String val2, float val3) {
       setVal1(val1);
       setVal2(val2);
       setVal3(val3);
       
       String result = validate();
       
       if (result != null) {
          rollback();
       }         
       else {
          commit();
       }      
       return result;

}

I'm curious: is this possible to do using only method-level transaction
attributes? Or do I need a UserTransaction?

Any advice would be much appreciated.

Thanks in advance,

--Joe

-- 
Joseph Barillari -- http://barillari.org


-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps1
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user


_____________________________________________________________________ 
Notice to recipient: 
The information in this internet e-mail and any attachments is confidential
and may be privileged. It is intended solely for the addressee. If you are
not the intended addressee please notify the sender immediately by
telephone. If you are not the intended recipient, any disclosure, copying,
distribution or any action taken or omitted to be taken in reliance on it,
is prohibited and may be unlawful. 

When addressed to external clients any opinions or advice contained in this
internet e-mail are subject to the terms and conditions expressed in any
applicable governing terms of business or client engagement letter issued by
the pertinent Bank of America group entity. 

If this email originates from the U.K. please note that Bank of America,
N.A., London Branch, Banc of America Securities Limited and Banc of America
Futures Incorporated are regulated by the Financial Services Authority.
_____________________________________________________________________ 




-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps1
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to