Hi Laszlo,
The only way I can make this code to fail with "id" being the class
property, is when id value is not explicitly assigned in the code. Cayenne
assumes that if a PK column is a part of the class, then the user is
responsible for setting it. So no automatic PK generation is done. When I
do something like "fto.setId(new Integer(123))", everything works
(including printout of the id value, and deleteObject).
This is strange actually, cause the behavior in my environment is so
different from yours. For instance, the failure that you've described
never happens in my test app. Rather the code may fail much earlier on
insert - since PK is null.
Is it possible that you have some unusual mapping for this entity? Are
there any Modeler validation warnings when you save the model?
Andrus
> Cayenne 1.0b4
> MySQL 4.12-max
>
> Hello Guys,
>
> I think I have noticed something strange. I am not sure if this is a
> bug, but I
> would like to have your opinion.
>
> If my object model in the cayenne modeler has no entry of the id
> (primary key
> of the entity) of the Photo Object. I can create and delete the
> persistance instance using the code below:
>
> DataContext mContext =
>
> Configuration.getSharedConfiguration().getDomain().createDataContext();
>
> Photo fto = (Photo)mContext.createAndRegisterNewObject("Photo");
>
> fto.setBestandsnaam("test.jpg");
> fto.setUrlPhoto("urlPhoto");
> fto.setUrlThumbnail("urlthumbnail");
>
> mContext.commitChanges(Level.WARN);
>
> ObjectId oi = fto.getObjectId();
>
> System.out.println("The object ID is: " +
> oi.getValueForAttribute("id"));
>
> mContext.deleteObject(fto);
> mContext.commitChanges(Level.WARN);
>
> However, if I do map the id in the modeler. The ObjectId will be null
> and this
> code throws a null pointer exception, when the object is to be deleted.
>
> If I just create the object and requery the datastore in another
> 'application', the ObjectId is
> there.
>
> The workaround is not to map the id and 'resolve' the id when needed,
> but it seems a bit strange.
>
> Does anyone have an idea?
>
> Thanks, Laszlo
This archive was generated by hypermail 2.0.0 : Mon Jun 30 2003 - 10:52:36 EDT