cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Frank" <>
Subject Re: New user PK id question
Date Thu, 01 Feb 2007 15:16:22 GMT
Thank you for the help.
I have more questions.

1. Does this go into the class extending your autogenerated class?
2. I removed the pk id from objEntity, but my table returns a null value for 

I am using the click framework also for my table.


----- Original Message ----- 
From: "Christian Mittendorf" <>
To: <>
Sent: Thursday, February 01, 2007 10:00 AM
Subject: Re: New user PK id question


Do not add the id to the properties exposed by the autogenerated object.
Just add the id property to the class extending your autogenerated class
and use


to return the pk for the object (may or may not work, I'm not sure how
auto_increment is handled by Cayenne in this case).

As an alternative, you may want to define another key for accessing the
object. In that case you have to make sure that this reference to the
object is a) unique and b) that the property is set if the object is
newly created:

public void setPersistenceState(int state)
// if the object was just created, set initial values
if (state == PersistenceState.NEW)
// Set all initial values here
Timestamp now = new Timestamp(System.currentTimeMillis());
String digest = "" + this.hashCode() + now.getTime();

Make the property "external_reference" a unique key. This does also
your application as the user cannot increment the id to see some
other objects
that he may not be allowed to see, if this kind of security is of


Am 01.02.2007 um 15:38 schrieb Frank:

> Yes,
> I get this error:
> Validation failure for "id"  is required.
> Frank
> ----- Original Message ----- From: "Peter Schröder" 
> <>
> To: <>
> Sent: Thursday, February 01, 2007 9:31 AM
> Subject: AW: New user PK id question
> did you set the pk-generation properly (database-generated) in the 
> modeler?
> -----Ursprüngliche Nachricht-----
> Von: Frank []
> Gesendet: Donnerstag, 1. Februar 2007 15:23
> An:
> Betreff: New user PK id question
> Hello,
> I have a mysql table with a PK of id that is auto incremented.
> The getter is not generated for this pk.
> I need to use the pk id in a table as a link to allow the user to  edit.
> If I add the pk id to the objEntity, whenever I try to add a  record, 
> cayenne complains that the pk id field cannot be blank
> I assign a value of 1 to the pk id and I can save the record.
> When I look at the record just added, the pk id show the correct  value 
> assigned by mysql(not 1)
> What am I doing wrong?
> I need theh id to add to the link.
> Thanks
> Frank

View raw message