cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <>
Subject Re: PK problem with Postgre
Date Fri, 21 Apr 2006 06:26:06 GMT

On Apr 21, 2006, at 4:42 AM, wrote:
>  When I was looking at the SQL statements Cayenne was using, it was  
> constantly
> trying to include the id - thus causing problems with Postgres's  
> autoincrement.
>  They seemed to think that Cayenne should just insert the record  
> and let
> postgres worry about doing the autoincrement.

This thread seems to be about two separate things - (1)  
autoincremented column values and (2) sequences used by Cayenne to  
generate PK. These are two different strategies (as mentioned in one  
of the messages that you quoted). Cayenne most certainly works with  
the second scenario (I am constantly using postgres myself)...

> In postgres, if  you want autoincrement you set the sequences up  
> and then you
> just insert a record without trying to predict what the next id  
> will be.
> Postgres should look after this.

Regarding the first scenario - can you elaborate how you setup your  
tables? One way that I know is this:

create sequence foo_bar_seq;
create table foo (bar integer unique not null default nextval 

(Or is this something else?) The example above does not work with  
Cayenne because Postgres driver as of 8.0 does not implement  
Statement.getGeneratedKeys() thus making it impossible (ok, rather  
very hard) for Cayenne to retrieve the key generated in such way. The  
solution - do not tie a PK column to a sequence in Postgres, let  
Cayenne generate the key.

I guess we may implement an equivalent of 'Statement.getGeneratedKeys 
()' on Cayenne end by using Postgres proprietary API to retrieve  
generated keys (and thus enable scenario (1)), still I hoped the  
driver would provide that.


View raw message