Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Concurrency Issue with HSQLDB

 
Shunjie Liu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
 
Kaydell Leavitt
Ranch Hand
Posts: 689
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic