Re: getGeneratedKeys() problem - Mailing list pgsql-jdbc

From Samuel Gendler
Subject Re: getGeneratedKeys() problem
Date
Msg-id AANLkTinffcDkExQ-CX393T6cxZXA3NcQhrrLm7MHThXE@mail.gmail.com
Whole thread Raw
In response to Re: getGeneratedKeys() problem  (Adam Todorski <atodorski@automate.com>)
List pgsql-jdbc
I had this problem, too.  I solved it by mapping my id column as a sequence instead of as 'identity'

        <id name="id" type="int" column="application_id">
            <generator class="sequence">
                <param name="sequence">portal.applications_application_id_seq</param>
            </generator>
        </id>

You could probably get away with creating the table with a serial column and just passing in the sequence that postgres implicitly uses, but I thought it safer to just explicitly declare the sequences that are used for ids.  This does mean that inserts require two queries, since there is no way to get the generated id in the same statement that does the insert, but I don't do bulk inserts via hibernate, so it doesn't much matter in my case.  

I'd definitely prefer to have cleaner mappings and not have to manually create/maintain the sequences, but this isn't the end of the world.  This is a pretty huge bug to have existed in the codebase for so long, though.  Personally, I never even reported it, as I thought it must be some kind of configuration error on my part since I didn't find any reference to the problem via google back when I looked (it was a while back - I was using pg 8.3.x at the time).


pgsql-jdbc by date:

Previous
From: Adam Todorski
Date:
Subject: Re: getGeneratedKeys() problem
Next
From: Emanuel Freitas
Date:
Subject: Exception in DriverManager.getConnection creates multiple connections in SYN_SEND state