Hi Andrus,
To answer your question: 'No, the modeler does not return any errors'.
I have created a test case that works like I described in my mail earlier.
1. run cre_tab.sql to create the table
2. run pk_support.sql to generate pk support
3. all java & cayenne stuff is located in /java.
The Class CreateMonkey is runnable and should give you this output:
WARN QueryLogger: --- will run 1 query. WARN QueryLogger: INSERT INTO
monkeys (id, name) VALUES (?, ?) WARN QueryLogger: [bind: NULL, 'Luke']
WARN QueryLogger: === updated 1 row. WARN QueryLogger: +++ transaction
committed. The value of the pk is: tst.Monkey: <id: null> WARN
QueryLogger: --- will run 1 query. WARN QueryLogger: DELETE FROM monkeys
WHERE id = ? WARN QueryLogger: [bind: NULL] WARN QueryLogger: === updated
0 rows. WARN QueryLogger: +++ transaction committed. INFO CreateMonkey:
Finished: Creating a monkey!
Thanks, Laszlo
BTW: No offense to anyone named Luke intended. ;-)
>From: "Andrus Adamchik" <andru..bjectstyle.org>
>Reply-To: andru..bjectstyle.org
>To: <cayenne-use..bjectstyle.org>
>Subject: Re: objectId seems not populated when the pk=objectId and mapped
>in the modeler
>Date: Mon, 30 Jun 2003 10:52:36 -0400 (EDT)
>
>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
>
>
>
>
_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail
This archive was generated by hypermail 2.0.0 : Mon Jun 30 2003 - 12:18:31 EDT