Program: 66767
Project: 66767
Buggy source:
/** 
 * INTERNAL: On persist and flush operations we must update any derived id fields.
 */
protected Object updateDerivedIds(Object clone,ClassDescriptor descriptor){
  if (descriptor.hasDerivedId()) {
    ObjectBuilder dependentBuilder=descriptor.getObjectBuilder();
    for (    DatabaseMapping derivesIdMapping : descriptor.getDerivesIdMappinps()) {
      DatabaseMapping derivedIdMapping=derivesIdMapping.getDerivedIdMapping();
      if (derivedIdMapping != null) {
        ClassDescriptor parentDescriptor=derivesIdMapping.getReferenceDescriptor();
        ObjectBuilder parentBuilder=parentDescriptor.getObjectBuilder();
        Object parentClone=derivesIdMapping.getRealAttributeValueFromObject(clone,this);
        if (parentClone != null) {
          Object key;
          if (parentDescriptor.hasDerivedId()) {
            key=updateDerivedIds(parentClone,parentDescriptor);
          }
 else {
            key=parentDescriptor.getCMPPolicy().createPrimaryKeyInstance(parentClone,this);
          }
          if (derivesIdMapping.hasMapsIdValue()) {
            Object aggregateClone=derivedIdMapping.getRealAttributeValueFromObject(clone,this);
            DatabaseMapping aggregateMapping=derivedIdMapping.getReferenceDescriptor().getMappingForAttributeName(derivesIdMapping.getMapsIdValue());
            aggregateMapping.setRealAttributeValueInObject(aggregateClone,key);
          }
 else {
            derivedIdMapping.setRealAttributeValueInObject(clone,key);
          }
          return key;
        }
      }
    }
  }
  return null;
}

Fixed version (ground truth):
/** 
 * INTERNAL: On persist and flush operations we must update any derived id fields.
 */
protected Object updateDerivedIds(Object clone,ClassDescriptor descriptor){
  if (descriptor.hasDerivedId()) {
    ObjectBuilder dependentBuilder=descriptor.getObjectBuilder();
    for (    DatabaseMapping derivesIdMapping : descriptor.getDerivesIdMappinps()) {
      DatabaseMapping derivedIdMapping=derivesIdMapping.getDerivedIdMapping();
      if (derivedIdMapping != null) {
        ClassDescriptor parentDescriptor=derivesIdMapping.getReferenceDescriptor();
        ObjectBuilder parentBuilder=parentDescriptor.getObjectBuilder();
        Object parentClone=derivesIdMapping.getRealAttributeValueFromObject(clone,this);
        if (parentClone != null) {
          Object key;
          if (parentDescriptor.hasDerivedId()) {
            key=updateDerivedIds(parentClone,parentDescriptor);
          }
 else {
            key=parentDescriptor.getCMPPolicy().createPrimaryKeyInstance(parentClone,this);
          }
          if (derivesIdMapping.hasMapsIdValue()) {
            Object aggregateClone=derivedIdMapping.getRealAttributeValueFromObject(clone,this);
            if (aggregateClone == null) {
              aggregateClone=derivedIdMapping.getReferenceDescriptor().getObjectBuilder().buildNewInstance();
              derivedIdMapping.setRealAttributeValueInObject(clone,aggregateClone);
            }
            DatabaseMapping aggregateMapping=derivedIdMapping.getReferenceDescriptor().getMappingForAttributeName(derivesIdMapping.getMapsIdValue());
            aggregateMapping.setRealAttributeValueInObject(aggregateClone,key);
          }
 else {
            derivedIdMapping.setRealAttributeValueInObject(clone,key);
          }
          return key;
        }
      }
    }
  }
  return null;
}