cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Gentry <>
Subject Re: "Can't get primary key from temporary id" :(
Date Wed, 08 Apr 2009 12:37:16 GMT
It sounds like you are trying to write a record into a log/audit
table.  Have you looked at MySQL triggers to do this?  The advantage
of using a trigger is that even if someone changes it outside of
Cayenne (the mysql> prompt, etc) the audit table will still be
populated.  Much safer to do it this way if you care about actual

As for exposing primary keys to the might be fine for a blog
or similar, but in the work I do it is a big taboo.  It identifies too
much information that could lead to a data breach if you have a
problem with your application's security.  I would only be
semi-comfortable exposing a primary key if it were encrypted by a
private key that changed per-session.

Just my thoughts...


On Tue, Apr 7, 2009 at 9:03 PM, Joseph Schmidt
<> wrote:
>> > Can't get primary key from temporary id
>> > ------------
>> >
>> > while trying to access the 'id' of a newly created
>> object entity A.
>> > I need this 'id' to write the value together with some
>> > other fields in some other object entity B inside the same
>> > transaction. Between A and B there's no relationship (I'm
>> > using MySQL as a DB and CayenneM5).
>> The primary key doesn't exist until the record is written
>> to the database, so you just can't do this. You have two
>> options:
>> * write the record to database, fetch it back again and
>> then you'll have the primary key
> Than this is not the same transaction :(.
>> * create a relationship between A and B
> In this particular case, there's no relationship because the
> 'id' from entity A is written to a text field in entity B together with other strings,
e.g. "Entity A with #id added at #date..."
> So it's impossible to map here a relationship :(.
> In other usage scenarios I have, e.g. for entity C, there's no Cayenne relationship because
it would mean to connect it with every other table.
>> If you find yourself using the primary keys directly very
>> often, you are probably not using Cayenne in the manner it
>> was intended. The idea is that it removes you from thinking
>> about database-centric issues like primary keys and just
>> think about objects and how they relate to each other.
>> Mostly.
> Well, I'm not sure about Cayenne, but the entire RESt architecture is based around the
idea of using 'id's to identify entities (but not just RESt).
> If Cayenne can't play simply with 'id's (and it's supposed to be used without them) than
I think it automatically excludes itself from most web applications :(, since most of them
rely on sending the 'id's back and forth.
> Is there no other way to get those IDs?
> How to do e.g. audit with Cayenne? Mostly the audit string or record must be in the same
transaction with with what they log.
> thanks,
> Joseph.

View raw message