Index: src/java/oracle/toplink/essentials/internal/descriptors/ObjectBuilder.java =================================================================== RCS file: /cvs/glassfish/entity-persistence/src/java/oracle/toplink/essentials/internal/descriptors/ObjectBuilder.java,v retrieving revision 1.16 diff -c -r1.16 ObjectBuilder.java *** src/java/oracle/toplink/essentials/internal/descriptors/ObjectBuilder.java 3 Oct 2006 19:58:32 -0000 1.16 --- src/java/oracle/toplink/essentials/internal/descriptors/ObjectBuilder.java 16 Oct 2006 05:19:46 -0000 *************** *** 57,62 **** --- 57,64 ---- protected Map mappingsByAttribute; protected Map mappingsByField; protected Map readOnlyMappingsByField; + // Secondary key field to Primary key field map (joined inheritance or secondary table) + protected Map primaryKeyFieldsBySecondaryField; protected Vector primaryKeyMappings; protected Vector primaryKeyClassifications; protected transient Vector nonPrimaryKeyMappings; *************** *** 1584,1589 **** --- 1586,1602 ---- throw DescriptorException.missingMappingForField(field, getDescriptor()); } + // GF#1153 + // If this entity is a child entity with JOINED inheritance strategy and Embedded Id, + // getting value with the primary key field of child table won't succeed + // for AggregateObjectMapping which only knows fields of root entity's table. + // Therefore we use the primary key field of the root entity. + if(getDescriptor().isChildDescriptor() && mapping.isAggregateObjectMapping()){ + DatabaseField primaryKeyField = (DatabaseField) getPrimaryKeyFieldsBySecondaryField().get(field); + if(primaryKeyField != null) { + field = primaryKeyField; + } + } return mapping.valueFromObject(domainObject, field, session); } } *************** *** 1739,1744 **** --- 1752,1768 ---- } /** + * INTERNAL: + * Return the secondary key field to primary key field map. + */ + public Map getPrimaryKeyFieldsBySecondaryField() { + if(primaryKeyFieldsBySecondaryField == null) { + primaryKeyFieldsBySecondaryField = new HashMap(); + } + return primaryKeyFieldsBySecondaryField; + } + + /** * Return the base value that is mapped to for given field. */ public Object getParentObjectForField(DatabaseField databaseField, Object domainObject) { *************** *** 1911,1916 **** --- 1935,1943 ---- this.getPrimaryKeyMappings().clear(); this.getNonPrimaryKeyMappings().clear(); + if (getDescriptor().hasMultipleTables()) { + this.getPrimaryKeyFieldsBySecondaryField().clear(); + } // This must be before because the scondary table primary key fields are registered after for (Iterator fields = getMappingsByField().keySet().iterator(); fields.hasNext();) { *************** *** 1947,1952 **** --- 1974,1982 ---- // This can be null in the custom multiple join case if ((secondaryField != null) && (mapping != null)) { getMappingsByField().put(secondaryField, mapping); + } + if (secondaryField != null){ + getPrimaryKeyFieldsBySecondaryField().put(secondaryField, primaryKeyField); } } }