• Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB Confusion (help the newbie)

 
Dan Lastoria
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am supporting a Struts based application that uses EJBs. I inherited this application and had no part in the design or coding. Anyone who did is now long gone.
The particular problem I am having seems to be related to some EJB confusion. Basically I have a customer entry screen. The application uses EJBs to store the customer for each session. Well, if I do an update of the customer then another user updates some other customer, the primary key gets re-used and I end up overwriting the original record.
So here's the steps that cause me problems:
Bring up a customer#1 initially (EJB gets created properly)
Do an update on that customer (update works, but now his CustomerID is stored somewhere)
Bring up customer#2
Update customer#2...
Now customer#1's CustomerID gets used but all of customer#2's information is written to it.
Here is some of the code where the problem surfaces:


[ August 28, 2003: Message edited by: Dan Lastoria ]
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Are key.getCustomerId() and customerVO.getCustomerId() returning the same value? If they aren't, find out where they get out of synch.
PS. You really should add some line wrapping on the SQL...
[ August 28, 2003: Message edited by: Lasse Koskela ]
 
Dan Lastoria
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, you're right...that looks awful. I fixed it up a bit.
key.getCustomerId() and customerVO.getCustomerId() do NOT return the same value. In fact that's exactly what I'm getting at here. The EJB is created using

"key" is constructed using myEntityCtx like this:

myEntityCtx is declared as:

I think it is in this context that the mistake is happening. I don't know enough about EJBs and/or Struts to know where to look from there. Any tips or suggestions would be greatly appreciated.
Thanks!
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are setting the EntityContext as expected in the setEntityContext(EntityContext ctx) method, right? I don't think the EntityContext is the problem.
Where and how are you a) initializing the customerVO object, and b) populating the customerId property of the customerVO?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!