Skip site navigation (1) Skip section navigation (2)

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: (view raw, whole thread or download thread mbox)
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">

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

pgsql-jdbc by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group