I was wrong - sorry for confusion. If you map a PK column as an
ObjAttribute, it is your responsibility to set the value of this
property before commit. This is consistent in Cayenne, whether the
column is generated or not. If you need *read-only* access to the id
value, you should use DataObjectUtils instead (possibly with a
manually created getter in the data object subclass). So current
Cayenne validation behavior is correct.
Andrus
On Feb 6, 2006, at 1:10 PM, Andrus Adamchik wrote:
> Good point. This looks like a bug. Could you open a bug report for
> that?
>
> Thanks
> Andrus
>
>
> On Feb 6, 2006, at 12:00 PM, Dave Merrin wrote:
>
>> Hi,
>>
>> I've had a look through some more Cayenne documentation and some
>> of the
>> source code. I discovered CayenneDataObject validation. I see I
>> can add my
>> own validation but I don't just want to wipe out all of the cayenne
>> validation by not calling the super implementation.
>>
>> I see in the Cayenne implementation the ObjAttributes are iterated
>> through,
>> getting the mapped DbAttribute and checking if the attribute is
>> mandatory.
>> Could an additional check be done at this point to check if the
>> DbAttribute
>> is generated before adding it to the failure list?
>>
>> Here is the code I am on about:
>>
>> Map failedDbAttributes = null;
>>
>> Iterator attributes = objEntity.getAttributes().iterator();
>> while (attributes.hasNext()) {
>> ObjAttribute objAttribute = (ObjAttribute)
>> attributes.next();
>> DbAttribute dbAttribute = objAttribute.getDbAttribute();
>>
>> Object value =
>> this.readPropertyDirectly(objAttribute.getName());
>> if (dbAttribute.isMandatory()) {
>> ValidationFailure failure =
>> BeanValidationFailure.validateNotNull(
>> this,
>> objAttribute.getName(),
>> value);
>>
>> if (failure != null) {
>>
>> if (failedDbAttributes == null) {
>> failedDbAttributes = new HashMap();
>> }
>>
>> failedDbAttributes.put(dbAttribute.getName(),
>> failure);
>> continue;
>> }
>> }
>>
>> Cheers,
>>
>> Dave
>>> -----Original Message-----
>>> From: Dave Merrin [mailto:dmerri..pasystems.co.uk]
>>> Sent: 06 February 2006 09:04
>>> To: cayenne-use..bjectstyle.org
>>> Subject: Query using foreign objects
>>>
>>>
>>> Hi,
>>>
>>> I have tried mapping an ObjEntity to to DBEntity to allow me to
>>> use primary
>>> keys in an expression. This works for the expression but creates
>>> a new
>>> problem. My primary key is an identity hence it is generated by
>>> the database
>>> (and marked as isGenerated=true in the mapping file).
>>> Unfortunately mapping
>>> the ObjEntity to the DBEntity makes Cayenne think I have to set
>>> primary key
>>> when creating a new record in the database.
>>>
>>> Is this a bug?
>>>
>>> As an alternative I tried using the db: prefix but this didn't
>>> seem to work
>>> across relationships.
>>>
>>> Is there any way to create expressions using primary keys?
>>>
>>> Cheers,
>>>
>>> Dave
>
>
This archive was generated by hypermail 2.0.0 : Tue Feb 07 2006 - 11:11:36 EST