• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Duplicate record problem

 
Ben Hagadorn
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a table in my Oracle database called Location. This table has two fields: LocationID Int (key), and LocationName String. I also have a JMS queue that receives requests to process Location records. It is possible to have messages queue up that have the same Location, in which case when I process the first message I need to create/insert a new Location and when I process the subsequent messages I need to use the Location created from the first message. So far, so good.

What I'm seeing is that if I have multiple messages queued up for a Location that does not yet exist, they all end up being inserted as new Locations. I'm not sure if this is the result of the way JMS works (asynchronous message processing?) or the way I've set up my hibernate files.

As a test, I print out the matching Location record count when I start my processing for the JMS queue, and also when I end. For new Locations, this is what I expect to see:

2006-06-07 09:41:52,186 INFO [STDOUT] >>> LOCATION RECORD COUNT @ START: 0
2006-06-07 09:41:52,192 INFO [STDOUT] >>> LOCATION RECORD COUNT @ END: 1
2006-06-07 09:41:52,286 INFO [STDOUT] >>> LOCATION RECORD COUNT @ START: 1
2006-06-07 09:41:52,292 INFO [STDOUT] >>> LOCATION RECORD COUNT @ END: 1
2006-06-07 09:41:52,386 INFO [STDOUT] >>> LOCATION RECORD COUNT @ START: 1
2006-06-07 09:41:52,392 INFO [STDOUT] >>> LOCATION RECORD COUNT @ END: 1
2006-06-07 09:41:52,486 INFO [STDOUT] >>> LOCATION RECORD COUNT @ START: 1
2006-06-07 09:41:52,492 INFO [STDOUT] >>> LOCATION RECORD COUNT @ END: 1
2006-06-07 09:41:52,586 INFO [STDOUT] >>> LOCATION RECORD COUNT @ START: 1
2006-06-07 09:41:52,592 INFO [STDOUT] >>> LOCATION RECORD COUNT @ END: 1


When I have multiple messages on the queue with the same Location I get this:

2006-06-07 09:41:52,186 INFO [STDOUT] >>> LOCATION RECORD COUNT @ START: 0
2006-06-07 09:41:52,186 INFO [STDOUT] >>> LOCATION RECORD COUNT @ START: 0
2006-06-07 09:41:52,241 INFO [STDOUT] >>> LOCATION RECORD COUNT @ START: 0
2006-06-07 09:41:52,250 INFO [STDOUT] >>> LOCATION RECORD COUNT @ START: 0
2006-06-07 09:41:52,257 INFO [STDOUT] >>> LOCATION RECORD COUNT @ START: 0
2006-06-07 09:41:52,621 INFO [STDOUT] >>> LOCATION RECORD COUNT @ END: 1
2006-06-07 09:41:52,651 INFO [STDOUT] >>> LOCATION RECORD COUNT @ END: 1
2006-06-07 09:41:52,667 INFO [STDOUT] >>> LOCATION RECORD COUNT @ END: 1
2006-06-07 09:41:52,681 INFO [STDOUT] >>> LOCATION RECORD COUNT @ END: 1
2006-06-07 09:41:52,695 INFO [STDOUT] >>> LOCATION RECORD COUNT @ END: 1

I think I need a way to lock down the Location table while I'm processing Location records so that I can make sure new records are inserted and commited before other processes can insert duplicates.

Does anyone have any ideas how I can tackle this?

Thanks for the help.

- Ben
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not an ORM question. Lets move it to EJB etc.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic