cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "WONDER" <mmmmmmmm...@web.de>
Subject Re: PK problem with Postgre
Date Fri, 21 Apr 2006 08:50:38 GMT
Indeed using the custom SEQ solved the problem. "At least till now".
I belive that Cayenne does not use the seq always using the Default
strategy.
i.e:
first insert Cayenne reads the seq. I see this in the log, where Cayenne
executes the SEQ. another time Cayenne doesnot executes the SEQ.

I think, its good idea if cayenne always uses the same strategy, and its
very good idea to make Cayenne create the needed Sequences if they does not
exist. I dont see any reason, why to do not create the seq automatically
using Cayenne and default strategy.

peaSakoe


----- Original Message ----- 
From: "Andrus Adamchik" <andrus@objectstyle.org>
To: <cayenne-user@incubator.apache.org>
Sent: Friday, April 21, 2006 8:26 AM
Subject: Re: PK problem with Postgre


>
> On Apr 21, 2006, at 4:42 AM, lsteele@iinet.net.au 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
> ('foo_bar_seq'));
>
> (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.
>
> Andrus
>
>
>
>
>


Mime
View raw message