persistence@glassfish.java.net

RE: part of an embedded object is read-only...

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Tue, 8 Aug 2006 15:44:46 -0400

Hello Sahoo,
   If you are getting the multiple writable mappings in this case then it seems the updatable=false, insertable = false is being ignored by the annotation processor, most likely because it is an embedded pk. Have you attempted to step through this code? Which mapping is causing the exception? Has the mapping within the AggregateObjectDescriptor (the embedded's descriptor) been marked as read-only ?

   Mappings within an Embeddable object can, individually, be marked as read-only. The entire object can also be marked read-only by making the embedded mapping (AggregateObjectMapping) read-only. The code you have included is checking for multiple writable mappings. This would be multiple mappings mapped to the same database column both of which could cause the column to be updated on the database. TopLink saves users from confusion by requiring that only one of the mapped attributes be writable. The check on isAggregateObjectMapping() prevents the error from occuring if one of the subsequent mappings is within an Embedded object. This code could be expanded to detect multiple writable mappings within an Embeddable as well, but would probably not resolve our issue here.
--Gordon

-----Original Message-----
From: Sanjeeb.Sahoo_at_Sun.COM [mailto:Sanjeeb.Sahoo_at_Sun.COM]On Behalf Of
Sanjeeb Kumar Sahoo
Sent: Monday, August 07, 2006 10:27 AM
To: Tom Ware; Yorke Gordon J
Cc: persistence_at_glassfish.dev.java.net
Subject: part of an embedded object is read-only...


(Resending as the earlier email which had a wrong subject.)

Hi Tom, Gordon,

I am looking into issue
https://glassfish.dev.java.net/issues/show_bug.cgi?id=894 . Looking at
the code I see that the metadata processing code is correctly processing
the insertable and updatable values that are specified in the Embeddable
class. An *AggregateObjectMapping* type of mapping is also created for
the embedded field. The bug seem to be in ObjectBuilder.java which is
reporting an incorrect exception. See code below from ObjectBuilder.java:
    public void initialize(AbstractSession session) throws
DescriptorException {
            ...
                if (!mapping.isReadOnly()) {
                    if (getMappingsByField().containsKey(field)) {
                        // We cannot determine if aggregate mapping for
the field are read-only, so ignore exception.
                        if (!mapping.isAggregateObjectMapping()) {
 
session.getIntegrityChecker().handleError(DescriptorException.multipleWriteMappingsForField(field.toString(),
mapping));
                        }
                    }
            ...

As you can see, from the above code, it is checking if the
AggregateObjectMapping is readonly or not. Should it not instead check
individual mapping objects that are part of the AggregateObjectMapping?
What I don't understand is why is their a boolean type field called
*isReadOnly* on an AggregateObjectMapping. What is the semantics of that
boolean flag? /Does TopLink Essential not support a part of an embedded
object to be read-only?/

Thanks,
Sahoo