Community
Participate
Working Groups
In TopLink we can specify properies for an individual mapping, this should be supported in EclipseLink-ORM.XML, too.
<properties> <property name="x" value="y"/> </properties> @Properties({ @Property(name="x", value="y") })
Here's xml and annotation definition for Property I am implementing: <xsd:complexType name="property"> <xsd:annotation> <xsd:documentation> A user defined mapping's property. @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface Property { /** * Property name. */ String name(); /** * String representation of Property value, * converted to an instance of valueType. */ String value(); /** * Property value type. * The value converted to valueType by ConversionManager. * If specified must be a simple type that could be handled by ConversionManager: * numerical, boolean, temporal, char or byte array. */ Class valueType() default String.class; } </xsd:documentation> </xsd:annotation> <xsd:attribute name="name" type="xsd:string" use="required"/> <xsd:attribute name="value" type="xsd:string" use="required"/> <xsd:attribute name="value-type" type="xsd:string"/> </xsd:complexType> It follows James' suggestion to allow specifying a simple value type - defaulted to String: <properties> <property name="x" value="y"/> <property name="z" value="1" value-type="Integer"/> </properties> @Properties({ @Property(name="x", value="y") @Property(name="z", value="1", valueType=Integer.class) }) Property and Properties annotations (and xml) could be assigned to any mapped attribute (that translates to DatabaseMapping's property) as well as to any Entity, Embeddable, MappedSuperclass (that translates to ClassDescriptor's property).
Created attachment 95427 [details] suggested patch (without tests).
Created attachment 95752 [details] The full patch containing all the changes: the fix and the tests.
Created attachment 95988 [details] The latest full patch (with tests). Produced a new patch after Guy's review: Just saw two things: 1 - When processing the Property annotations you need to use the invokeMethod call on the member variables. That is, as an example: propertyMetadata.setName(MetadataHelper.invokeMethod("name", property)); 2 - In MetadataAccessor constructor if XMLEntityMappings is not null but the properties list is null then you should look for annotations in the ClassAccessor case. For the other mappings the code is correct (since we do mapping level override). Cheers, Guy The biggest part of the change was to make sure that xml-defined and annotation-defined properties on a class are merged.
Posting my feedback to Andrei for consideration: Couple things: 1 - In XMLEntityMappingsMappingProject make sure that you are adding the mappings in the order they are defined in the schema (you might be already, but it's hard to tell from the diff file so I just wanted to double check). This must be done otherwise on write out we will break the schema validation. 2 - When you are processing the property list and don't add one because another property with the same name is already defined, you don't log a warning message in an override case? What if two properties with the same name are defined in the same place? This should throw an exception no? 3 - I don't see any of your new files in the diff? I assume you added a new MetadataHelper? And the new MappingAccessor? Cheers, Guy
I would expect the properties on the descriptor (entity) and mappings to work like a map where the last property put overrides any previous values. In the case where a previous value exists it would be nice if we could log the situation at a verbose level such as FINER/FINEST indicating the value x is replacing a previously set value of y for the given property name. I assume that this bug is assigned so I am changing the state from NEW to ASSIGNED
Following the pattern in metadata processing code will log a warning in case property value is overridden.
Created attachment 96136 [details] The latest patch - added warnings. The latest patch deals with properties' values overriding: added warnings when that happens, also made sure that the last property overrides the first one.
Please make sure that the JavaDocs for the @Property annotation explains the precedence so tat a developer using annotations and XML will know how a property could be overridden.
To clarify my previous statement. Having a property of the same name in annotations and XML should result in a logged message (@ FINER or FINEST) and the XML property value should be used. If two properties exist with the same name in annotations an exception should be thrown to remain consistent with JPA processing of annotations like @NamedQuery. If two properties exist with the same name in XML an exception should be thrown.
Created attachment 96266 [details] The latest patch - added exceptions As per Doug's posting an exception now thrown in case two same-named properties applied to the same master in either orm xml or annotations.
Checked in the latest patch. Reviewed by Guy. Tests are in FullRegressionTestSuite: for annotations it's AdvancedJPAJunitTest.testProperty for annotations and EntityMappingsAdvancedJUnitTestCase.testProperty for xml (for the latter specify -Dorm.testing=eclipselink)
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink