| Re: [eclipselink-users] [MOXy] setting bi-directional references during unmarshalling |
|
Hey Polly, We're currently working on better support for handling bi-directional relationship mappings in EclipseLink. Currently in EclipseLink 1.2 (which is available today) for containment relationships, you can configure the mapping to automatically set the back-reference when it's populating the collection. This functionality isn't currently exposed in the MappingWorkbench but is available through the mapping APIs, Project XML and in JAXB through a custom annotation. Using the mapping APIs you would do something like: XMLCompositeCollectionMapping childMapping = new XMLCompositeCollectionMapping(); childMapping.setXPath("children/child"); childMapping.setReferenceClass(Child.class); //Specify the name of the attribute on the reference class that points back to the container object childMapping.setContainerAttributeName("parent"); childMapping.setContainerGetMethodName("getParent"); childMapping.setContainerSetMethodName("setParent"); parentDescriptor.addMapping(childMapping); If you're using Project XML, this can also be specified in the xml version of the project using the <container-attribute> element on the composite mapping. In EclipseLink 1.2 this support is only availabe for Containment based mappings (XMLCompositeObjectMapping and XMLCompositeCollectionMapping), but EclipseLink 2.0 will have expanded support for bi-directional relationships to also include reference mappings. Hope this helps, -Matt polly.c.chang wrote:
|