I have one CMP named, EmpTest having composite PK as, empId & empSurname. I have finderHelper on field called, empName. From my stateful session bean, TxnSupport, having Txn attribute, TX_BEAN_MANAGED & isolation level as, TRANSACTION_REPEATABLE_READ. In this bean, from session context i am deriving UserTransaction. So I am having corresponding, userTrans.begin(); #CODE BLOCK on error userTrans.rollback(); userTrans.commit(); There is a loop between begin & commit. #CODE BLOCK - is First time, I make findByName, I dont get the record, so I create new one. In the same transaction, next time, I execute same findByName, still I dont get the record. (This surprises me !) But then at the time of creation of record, it says Duplicate Key Exception, & transaction rolled back. So Qn is in the first pass record is not found, so it creates a new one, then in the second time why it doesnt get that record ? Though then record is not there, then why it doent let it to be added ? Why it gives Duplicate record exception ? My environment is : IBM VAJ 3.5 IBM DB2 6.0 Can anyone throw light on this ?
Hi, I guess its the isolation level problem. TRANSACTION_REPEATABLE_READ does not allow you to read the newly created or updated records in database. Try to decrease the strength of isolation level and try it. Good luck. Please let me know if it works.
Ram Dhan Yadav (SCJP, SCWCD, SCJA-I, IBM EC(483))
"We are what we repeatedly do. Excellence, then, is not an act, but a habit."
Does it matter what the isolation level is since this is being done within the same transaction? What if you use the pk from the first pass and during the second just say findByPrimaryKey will this find the data?
Ram Dhan Yadav K
Joined: Aug 13, 2001
Does it matter what the isolation level is since this is being done within the same transaction? Actualy i have never tested different isolation levels, its my guess based on the information given by Shivaji. Isolation level does matter though with the same transaction , accroding to documentaion of isolation levels. I will try to post the stuff once i come across it.