• 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

Duplicate record problem

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not an ORM question. Lets move it to EJB etc.
 
reply
    Bookmark Topic Watch Topic
  • New Topic