Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 325701

Summary: DynamicTypeBuilder needs an addUnidirectionalOneToManyMapping-method
Product: z_Archived Reporter: Frank Schwarz <fs5>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P3 CC: eclipselink.orm-inbox, michael.f.obrien
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on: 325699    
Bug Blocks:    

Description Frank Schwarz CLA 2010-09-19 12:27:14 EDT
Build Identifier: Trunk

DynamicTypeBuilder is missing a method to add an *unidirectional* one-to-many-mapping. A normal one-to-many-mapping when applied unidirectionally will miss foreign key updates.


public UnidirectionalOneToManyMapping addUnidirectionalOneToManyMapping(
    String name, DynamicType refType, String... fkFieldNames) {
    if (fkFieldNames == null || getType().getDescriptor().getPrimaryKeyFields().size() != fkFieldNames.length) {
        throw new IllegalArgumentException("Invalid FK field names: " + fkFieldNames + " for target: " + refType);
    }

    UnidirectionalOneToManyMapping mapping = new UnidirectionalOneToManyMapping();
    mapping.setAttributeName(name);
    mapping.setReferenceClass(refType.getJavaClass());

    for (int index = 0; index < fkFieldNames.length; index++) {
        String targetField = getType().getDescriptor().getPrimaryKeyFields().get(index).getName();
        mapping.addTargetForeignKeyFieldName(fkFieldNames[index], targetField);
    }

    mapping.useTransparentList();

    return (UnidirectionalOneToManyMapping) addMapping(mapping);
}


Reproducible: Always
Comment 1 Eclipse Webmaster CLA 2022-06-09 10:27:35 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink