Hi,
my application need to generate a "parent" object and then create a "child"
object that contains the PK value of the parent.
I'm using MySQL and the colum "id" is "autoincrement". ( both tables )
So first i create the main object (it extends DataObject ):
MainObject mainObj = new MainObject();
//setting properties... without id.. it's generated by mysql
mainObj.set......
....
...
DataContext...registerNewObject(MainObject);
DataContext...commitChanges();
The record is succesfully inserted in the database!
Then i need to get the PK... in this case a single column ( Long ).
If i insepct the corresponding filed it is empty, so i see in the
documentation that there are two ways to perform this task:
http://cayenne.apache.org/doc30/accessing-pk-and-fk-values.html
public Long getMainObjectId() {
return (getObjectId() != null && !getObjectId().isTemporary()) ? (Long)
getObjectId().getIdSnapshot().get(ID) : null;
}
http://cayenne.apache.org/doc30/dataobjectutils.html
long myId = (Long)DataObjectUtils.pkForObject(MainObject);
but, with both techniques the value returned is "null"!
What is wrong?
Thansk for support.
Davide
This archive was generated by hypermail 2.0.0 : Mon Aug 09 2010 - 16:12:23 UTC