• 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

Concurrency Issue with HSQLDB

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello.
I am using IDENTITY to auto-generate my ID in one of my tables
and using CALL IDENTITY() to get back the newly created ID.

However, as I am doing this over a network. I noticed that my JDBC code
executes CALL INDENTITY() before my INSERT INTO ... statement is completed and thus returning the the incorrect ID.

when I put a sleep() for 5 sec, everything works fine. So I suppose its a problem with concurrency issue.

I am wondering is there any method to ensure when I call the CALL IDENTITY() function, it will return me the correct id ? A method that when updating the database, the CALL IDENTITY will be blocked before the INSERT statement is completed ?

Thank you
 
Ranch Hand
Posts: 694
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is my insert method. It works in single-user, I have not tried multi-user yet but I believe that it should work. This method makes a couple of assumptions: 1) only one record is inserted in the query, and 2) that the auto-generated key is a long (a BIGINT).


[ July 10, 2007: Message edited by: Kaydell Leavitt ]
 
Shunjie Liu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.

I am sure your code works for mySQL or other heavy weight database.
but this HSQLDB don't support that...oh well have to keep trying
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic