• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Strange Problem with Txn.

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Ranch Hand
Posts: 321
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 321
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Steve,

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.
 
Do you want ants? Because that's how you get ants. And a tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic