Hi,

I've got a trivial piece of code:

---

        public synchronized long insertVertex() throws SQLException
        {
                Statement st = con.createStatement();
                st.executeUpdate("INSERT into vertices () VALUES () ",
Statement.RETURN_GENERATED_KEYS);
                ResultSet results = st.getGeneratedKeys();

                if (results.next())
                {
                        return results.getLong(1);
                }

                throw new SQLException("Could not retrieve latest vertices.id");
        }

---


Now the issue is that this mostly returns the generated index when
executed quickly in succession, but not always. I tried to create a
testcase, with two threads, but have failed to recreate the issue thus
far.
I am thus not able to reliably retrieve the generated indices. This
issue occurs with multiple tables, but also with a table with a single
column called `id':

---
CREATE TABLE vertices (id IDENTITY PRIMARY KEY);
---

This is with h2 version 1.3.165. I've looked at the changelog of
1.3.166, but didn't see any relevant fixes wrt my problem. It looks
like some kind of concurrency issue, but I don't know how to address
it with h2. I'm running an application that does multiple updates,
delete from's and inserts at the same time in different threads on
multiple tables, but the affected method is synchronized, so I don't
understand why that would be an issue.

java version "1.7.0_03"
Java(TM) SE Runtime Environment (build 1.7.0_03-b04)
Java HotSpot(TM) 64-Bit Server VM (build 22.1-b02, mixed mode)

Thanks in advance,
Thomas

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to