-
1. Re: Many SQL for getXXX method
dsundstrom Aug 27, 2002 6:18 PM (in response to jaime)You have discovered why transactions are required. The system must reload data at the begining or each transaction, because it may have changed since the last transaction comitted. If you want to use a POJO, you will need to manage the transaction by hand with a UserTransaction.
-
2. Re: Many SQL for getXXX method
jaime Aug 27, 2002 6:55 PM (in response to jaime)Ok,
but how I can find an example of using UserTransaction???
Thanks
JaimeS -
3. Re: Many SQL for getXXX method
jtorres Aug 28, 2002 12:55 AM (in response to jaime)The following code snippet shows the use of a UserTransaction:
[pre]
//obtain a user transaction
InitialContext ctx = new InitialContext();
UserTransaction ut = null;
try{
ut = (UserTransaction)ctx.lookup("UserTransaction");
//start transaction
ut.begin();
... some code ...
//commit the transaction
ut.commit();
}catch(Exception e){
if(ut != null){
//rollback if an unexpected exception occurs
ut.rollback();
}
[/pre]
Hope this helps -
4. Re: Many SQL for getXXX method
tdang Aug 28, 2002 4:03 AM (in response to jaime)In which package is the class UserTransaction located?
Thanks! -
5. Re: Many SQL for getXXX method
jtorres Aug 28, 2002 10:43 AM (in response to jaime)UserTransaction is in javax.transaction. If you are using JBoss 3.x, you can reference the jar in $JBOSS_HOME/server/default/lib/jboss-j2ee.jar.
-
6. Re: Many SQL for getXXX method
jaime Aug 28, 2002 11:54 AM (in response to jaime)Thanks
It's work perfectly but I have some limitation.
If I try to use my EJB inside a JSP file, I need begin and end a transaction, it's not like me. read some articles and I found that another solution is set COMMIT-OPTION to A, but I set this option in the xml file, but I restar JBoss and I have the same problem (with out a transaction).
Where I need to set COMMIT-OPTION to A value???
Thanks
JaimeS -
7. Re: Many SQL for getXXX method
dsundstrom Aug 28, 2002 4:12 PM (in response to jaime)You set commit options in the jboss.xml file.
I strongly suggest you don't manualy manage transactions in you code. It is not good desing. Instead you could create a servlet filter that starts a tx on the way in and commits it on the way out. Also you need to check the current state of the tx before comitting, and you need a ton of exception handling code. Another option is to use value objects for you beans and access them in the jsp.