Re: getGeneratedKeys() problem

From: Samuel Gendler <sgendler(at)ideasculptor(dot)com>
To: Adam Todorski <atodorski(at)automate(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org, viktor(dot)pravdin(at)disi(dot)unitn(dot)it
Subject: Re: getGeneratedKeys() problem
Date: 2010-10-26 17:35:10
Message-ID: AANLkTinffcDkExQ-CX393T6cxZXA3NcQhrrLm7MHThXE@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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).

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Emanuel Freitas 2010-10-29 14:21:39 Exception in DriverManager.getConnection creates multiple connections in SYN_SEND state
Previous Message Adam Todorski 2010-10-26 14:41:36 Re: getGeneratedKeys() problem