cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gentry, Michael \(Contractor\)" <michael_gen...@fanniemae.com>
Subject RE: PK problem with Postgre
Date Fri, 21 Apr 2006 13:11:51 GMT
When Cayenne reads the sequence value the first time, it caches 20 keys
internally (although you can change 20 to a value appropriate for your
application, just make sure the value you tell Cayenne to use matches
the increment_by attribute of the PostgreSQL sequence).  The next 19
inserts into that table do not require a trip to the database to fetch a
primary key, thus speeding up inserts.  This is why you don't see
Cayenne accessing the sequence on the second insert.  Also, the Cayenne
Modeler will generate the sequences for the tables for you, but you can
still do it by hand.

Hope that helps,

/dev/mrg


-----Original Message-----
From: mmmmmmmmm53@web.de [mailto:mmmmmmmmm53@web.de] 
Sent: Friday, April 21, 2006 4:51 AM
To: cayenne-user@incubator.apache.org
Subject: Re: PK problem with Postgre


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