This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 217168 - Add mapping's properties support to the EclipseLink-ORM.XML Schema
Summary: Add mapping's properties support to the EclipseLink-ORM.XML Schema
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard: Fixed in 1.0M8
Keywords:
Depends on:
Blocks: 200040
  Show dependency tree
 
Reported: 2008-01-30 16:31 EST by Andrei Ilitchev CLA
Modified: 2022-06-09 10:21 EDT (History)
3 users (show)

See Also:


Attachments
suggested patch (without tests). (39.32 KB, patch)
2008-04-09 17:14 EDT, Andrei Ilitchev CLA
no flags Details | Diff
The full patch containing all the changes: the fix and the tests. (72.07 KB, patch)
2008-04-11 16:32 EDT, Andrei Ilitchev CLA
no flags Details | Diff
The latest full patch (with tests). (78.81 KB, patch)
2008-04-14 16:17 EDT, Andrei Ilitchev CLA
no flags Details | Diff
The latest patch - added warnings. (98.48 KB, patch)
2008-04-15 14:18 EDT, Andrei Ilitchev CLA
no flags Details | Diff
The latest patch - added exceptions (103.95 KB, patch)
2008-04-16 10:57 EDT, Andrei Ilitchev CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrei Ilitchev CLA 2008-01-30 16:31:43 EST
In TopLink we can specify properies for an individual mapping, this should be supported in EclipseLink-ORM.XML, too.
Comment 1 Doug Clarke CLA 2008-02-07 15:04:38 EST
     <properties>
        <property name="x" value="y"/>
     </properties>


@Properties({
   @Property(name="x", value="y")
})
Comment 2 Andrei Ilitchev CLA 2008-04-09 12:16:12 EDT
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).
Comment 3 Andrei Ilitchev CLA 2008-04-09 17:14:42 EDT
Created attachment 95427 [details]
suggested patch (without tests).
Comment 4 Andrei Ilitchev CLA 2008-04-11 16:32:37 EDT
Created attachment 95752 [details]
The full patch containing all the changes: the fix and the tests.
Comment 5 Andrei Ilitchev CLA 2008-04-14 16:17:42 EDT
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.
Comment 6 Guy Pelletier CLA 2008-04-15 09:53:16 EDT
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
Comment 7 Doug Clarke CLA 2008-04-15 09:57:37 EDT
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
Comment 8 Andrei Ilitchev CLA 2008-04-15 10:20:16 EDT
Following the pattern in metadata processing code will log a warning in case property value is overridden.
Comment 9 Andrei Ilitchev CLA 2008-04-15 14:18:43 EDT
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.
Comment 10 Doug Clarke CLA 2008-04-15 14:46:20 EDT
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.
Comment 11 Doug Clarke CLA 2008-04-15 15:23:46 EDT
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.
Comment 12 Andrei Ilitchev CLA 2008-04-16 10:57:46 EDT
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.
Comment 13 Andrei Ilitchev CLA 2008-04-16 12:01:36 EDT
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)
Comment 14 Eclipse Webmaster CLA 2022-06-09 10:21:46 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink