You can't uncheck mandatory checkbox for a PK.

As to the original problem, I am pretty sure I am not seeing this behavior in Cayenne 3.0. Could be a bug in 2.0.4. Would it be possible to try it out with 3.0?

Andrus


On Jun 18, 2009, at 6:39 PM, Michael Gentry wrote:

I'm going to take a guess that the isMandatory="true" is firing first
before the PK is generated and assigned.  Try turning that off and see
if it works.  Cayenne should know that PKs are mandatory, anyway.

mrg


On Wed, Jun 17, 2009 at 5:17 PM, Mark Fraser<[email protected]> wrote:
Hello,

I am using Cayenne 2.0.4 with Derby embedded.

I am getting a ValidationException "id is required" when I commit changes
after creating a new object.

I have set the PK Generation Strategy to Database-Generated and set the ID
field as Auto Incremented in the modeler.

In my map file the id field looks like this:

...db-attribute name="ID" type="INTEGER" isPrimaryKey="true"
isGenerated="true" isMandatory="true" length="10"....


I have also tested whether Cayenne thinks the adapter supports generated
keys with the following code:


  DataMap map = dataContext.getEntityResolver().getDataMap("MyMap");
DataNode node = dataContext.getParentDataDomain().lookupDataNode(map);
  DbAdapter ad = node.getAdapter();
  System.out.println(ad.supportsGeneratedKeys());
 and this returns true.

If I uncheck "Object Validation" for the data domain in the modeler
everything works fine.

However I would rather not turn off object validation.

Anyone have any suggestions on what I might be missing?

Thanks,

Mark



Reply via email to