aspose file tools
The moose likes EJB and other Java EE Technologies and the fly likes Help needed ...User Transaction problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Reply Bookmark "Help needed ...User Transaction problem" Watch "Help needed ...User Transaction problem" New topic
Author

Help needed ...User Transaction problem

Parthiv Patel
Greenhorn

Joined: Feb 10, 2003
Posts: 10
I am new to using JTA...cannot conclude what's wrong the code here.
my goal is to do transaction commits and rollbacks at regular intervals.to put more detail
say..if I have a database table with only two columns(Key, Data) and given a array of 14 keys the records of which I want to update at regular intervals..
for example if the interval is 3
after updating records 1 to 3 ..I do a commit/rollback
after updating records 4 to 6 ..I do a commit/rollback
after updating records 7 to 9..I do a commit/rollback
after updating records 10 to 12..I do a commit/rollback
finally after updating records 13, 14 I do a commit/rollback

here's a code snippet..
UserTransaction ut = null;
int y = keyarray.size();
int i = 0; utinterval = 3;
while(i < y)
{
if(ut == null)
{ ut = mySessionContext.getUserTransaction();
ut.begin();
}
Statement updatest = conn.createStatement();
do update....
updatest.close();
if(i == utemp);
{
ut.commit or ut.rollback;
utemp = utemp + utinterval;
ut = mySessionCtx.getUserTransaction();
ut.begin();
}
}//end of while loop
ut.commit() or rollback.
I have tried doing this using DB2 and Oracle..
the problem is..
after I do a rollback if there is atleast one commit then the whole thing gets committed.
for example
for records 1 , 2, 3 after update I did rollback
for records 4, 5, 6 after update I did a rollback
for records 7, 8, 9 after update I did a commit
records 1, 2, 3, 4, 5, 6 all show the committed value.
I am not sure what's wrong with this code..
any advise/suggestion greatly appreciated.
-PP
Parthiv Patel
Greenhorn

Joined: Feb 10, 2003
Posts: 10
Hi all,
wanted to add some more observations..
(Bean managed transactions, Websphere Studio Application Developer Test environment, DB2 UDB 7.2 )
To rephrase the problem...
all I am trying to do is
open a transaction
do some updates
close (commit/rollback) a transaction
Open a new transaction
do some updates
close a transaction
so on......
at regular intervals...
If I do rollbacks all the way down,i.e I do rollbacks for all transactions..then it works
but when I follow a Rollback with a Commit in the next transaction..it doesn't work, the rolled back update actually does a commit.
Can anyone help me out...THIS IS THE CRITICAL PATH in my project..and it is URGENT too..
Thanks in advance
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Help needed ...User Transaction problem
 
Similar Threads
mdb and transactions
EJB transaction issue
BMT not propogated to invoked beans
Programmatic Transactions
UserTransaction and setRollbackOnly