• 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

ahh! ejb3 web services with multiple clients and transaction security! please help!

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a web service that is producing some confusing and destructive behavior. I believe it has some sort of issue with how I am handling transactions. Everything works beautifully when using one test client, but when I try to simulate a production environment by having multiple test clients make concurrent calls, things quickly go wrong. My code looks something like (sans lots of annotations and syntactical stuff):

Summary: the service facilitates the persisting of data into 2 entites: 'User' and 'Stuff';. The user has a 'userId'; (this is a unique id) and a set of child entities 'stuffs'. The 'Stuff&' has a parent entity's 'userId' and some other stuff. The service exposes one method that takes a list of 'Request' objects. The 'Request' object holds either a 'Stuff' or 'User' object and an Action enum: {ADD_USER, ADD_STUFF...}. The service iterates the list of requests and for each request it: checks the enum, and then performs the appropriate action on the appropriate object (if Action=ADD_USER, request.user will be added to database...)

Issue: in the ADD_STUFF case, i want to check to make sure the stuff's parent user exists, if it doesn't, then I want to add it. (The User entity is fairly simple, most of its attributes aren't important other than userId, which the stuff object has. So, if someone is silly enough to make an attempt to add some stuff to a non-existent user, I'm nice enough to add a 'dummy' user in order to allow the adding of the child entity). This works perfectly with only one test client running. The problem that gets caused by multiple clients is explained below.


some code:







I expect most requestLists will be a request to add a User and then requests to add all his stuff. Which is what my test clients are doing. They look something like




Problem: sql unique exceptions occur!!! what seems to happen is: test1 starts and adds its user. then test2 starts and adds its user. then test1 trys to add its first stuff, but for some reason the checkForUser call doesn't find anyone, so it trys to add a dummy user, which results in a unqiue_key violation exception on that userId. So test1's transaction gets rolled back, test2's transaction then completes successfully.

I would happy to provide any other details. please help!


Thanks


 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic