I try to create ObjectArrayMapping using DescriptorCustomizer:
public class MyDescriptorCustomizer implements DescriptorCustomizer {
public void customize(ClassDescriptor descriptor) throws Exception { // Set class descriptor to an aggregate collection. descriptor.descriptorIsAggregateCollection(); // Delete old mapping (default) for my attribute: descriptor.removeMappingForAttributeName("attributeNa开发者_运维知识库me"); // Create new ObjectArrayMapping: ObjectArrayMapping arrayMapping = new ObjectArrayMapping(); // Set up properties. arrayMapping.setReferenceClass(MyClass.class); arrayMapping.setAttributeName("attributeName"); arrayMapping.setFieldName("fieldName"); arrayMapping.setStructureName("structureName"); // Add mapping to descriptor. descriptor.addMapping(arrayMapping); } }
Problem is the following: ObjectArrayMapping requires Class Descriptor to be an AggregateCollection, that's why I set this property for my descriptor.
But after it all other mappings (for other fields) which were of DirectToFieldMapping type are lost, cause they require normal descriptor. Do you have any ideas how to avoid this problem? Any help will be appreciated. If you need Entity code or smth else, I can add it. Thanks.ObjectArrayMapping requires the target descriptor be aggregate (not aggregate collection), but more specificly requires that it map a Struct, not to a table.
You seem to be making the source descriptor aggregate collection, that is wrong, you need to make the target aggregate (i.e. Embeddable, so just map it as an @Embeddable in JPA). You will also need to define a DescriptorCustomizer to set the structureName and the fieldOrdering.
Or if using 2.3 you can use the @Struct annotation and the @Array annotation to define the ObjectArrayMapping, you should not need any customizers.
http://wiki.eclipse.org/EclipseLink/Examples/JPA/PLSQLStoredFunction
精彩评论