• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting duplicates with mixed-match data using hibernate

 
laura mccord
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using hibernate to add/update records and every once in a while I get a duplicate with a mix-match of user data as if someone else's data is merging with another person's record. I don't know what is causing this but I'm thinking it may be my lack of knowledge as to when to use merge() vs saveOrUpdate(). Could one of these cause this kind of behavior? I've read that merge() will update a detached object...could it be that I have some data stuck in memory from another person's session that is causing this problem? If I use saveOrUpdate() will this fix the issue?

Any suggestions are greatly appreciated. I have been trying to figure out why this is happening. 95% of the time everything works but every month there are a small handful that this occurs and I have to reconcile it.

Thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Laura,
It's hard be sure since this is a specific scenario. But yes, using merge() instead of persist() could cause problems. merge() is meant for detached objects. Since you are having "out of sync" problems, this could be part of it. Have you seen this explanation?
 
laura mccord
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a little new to me so I keep having to read it to get the hang of its uses. What I am finding is that with the pop-up I wrote it seems like a user might be not logging out of the application that it is originating from, or not closing out the browser when they are completed with the application, or something to that effect because now I'm thinking that the conflict is also because the session data is not clearing out. I think what is happening is that someone is coming up behind another person and receiving the pop-up with the data from the person before them. And, they are making selections thinking it applies to them when in fact it doesn't. So even though I'm creating new objects it's as if it's taking a mixture of data between users from the database and the attributes that are received from login and creating duplicates.

I was able to eliminate the duplicate objects from the main Person record by replacing merge with saveOrUpdate() but the one-to-many objects that it refers to are now duplicating, which are the Person's items that they are selecting from the pop-up selection list. When the person makes an item selection it should update their item with 'yes'. But, in case it is updating the items but also creating new ones with 'no'. Perhaps, removing the merge() and replacing it with the saveOrUpdate() now from that section may solve it.

So for example



If you have any further suggestions I'd appreciate it.

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic