Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 325701 - DynamicTypeBuilder needs an addUnidirectionalOneToManyMapping-method
Summary: DynamicTypeBuilder needs an addUnidirectionalOneToManyMapping-method
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 enhancement with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 325699
Blocks:
  Show dependency tree
 
Reported: 2010-09-19 12:27 EDT by Frank Schwarz CLA
Modified: 2022-06-09 10:27 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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