cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joseph Schmidt <>
Subject Re: "Can't get primary key from temporary id" :(
Date Wed, 08 Apr 2009 01:03:55 GMT

> > 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.



View raw message