Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 356292

Summary: Validation error for entities with @AttributeOverride on attribute marked as @Version in mapped superclass
Product: [WebTools] Dali JPA Tools Reporter: Martin Keschenau <martin.keschenau>
Component: JPAAssignee: Karen Butzke <karenfbutzke>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P2 CC: cbridgha, david_williams, jolene.moffitt, neil.hauge, raghunathan.srinivasan
Version: 3.0Flags: david_williams: pmc_approved+
raghunathan.srinivasan: pmc_approved+
neil.hauge: pmc_approved? (naci.dai)
neil.hauge: pmc_approved? (deboer)
neil.hauge: pmc_approved? (neil.hauge)
neil.hauge: pmc_approved? (kaloyan)
cbridgha: pmc_approved+
neil.hauge: review+
Target Milestone: 3.0.1   
Hardware: PC   
OS: Windows XP   
Whiteboard: PMC_approved
Attachments:
Description Flags
Demo code for mapped superclass A
none
Demo code for entity B
none
proposed patch against 3.0 maintenance none

Description Martin Keschenau CLA 2011-08-31 05:26:48 EDT
Build Identifier: 20110615-0604

Let B be an entity class, which inherits from a @MappedSuperclass A. A defines a numeric version column called "version" and annotated with @Version. B uses an @AttributeOverride annotation for overriding the column name of the version attribute.

For this case, the JPA validation reports the following error on class B:

Attribute override "version" cannot be resolved to an attribute on the mapped superclass "A"

However, no validation error should be produced here. This scenario used to be validated successfully in Eclipse versions prior to 3.7.


Reproducible: Always

Steps to Reproduce:
1. Create a JPA project, so that JPA validation can be used.
2. Create two entities implementing this scenario (see attached files).
3. Run validation.
Comment 1 Martin Keschenau CLA 2011-08-31 05:28:33 EDT
Created attachment 202491 [details]
Demo code for mapped superclass A
Comment 2 Martin Keschenau CLA 2011-08-31 05:28:59 EDT
Created attachment 202492 [details]
Demo code for entity B
Comment 3 Karen Butzke CLA 2011-09-01 09:11:29 EDT
Thanks for reporting this one Martin! In Eclipse 3.7 Dali attempted to enhance our existing validation support with a number of new errors. In this case it appears we have taken the spec too literally when it says "The AttributeOverride annotation is used to override the mapping of a Basic (whether explicit or default) property or field or Id property or field." in section 11.1.4.

For the 3.0.1 release we should open up attribute overrides to allow version mappings.

For a future release we probably need to add another validation for overriding a mapping that is not a correct type (Basic, Id, or Version). It is confusing to have the error that the attribute override cannot be resolved, when the attribute does exist.
Comment 4 Karen Butzke CLA 2011-09-01 09:27:42 EDT
As a workaround until 3.0.1 is released you can turn off this particular validation. In the workspace preferences under JavaPersistence->JPA->Errors/Warnings find 'Attribute override name cannot be resolved to an attribute', it's the 2nd error under Database->Attribute/association overrides. Set this to 'Ignore'.
Comment 5 Karen Butzke CLA 2011-09-01 13:17:41 EDT
Created attachment 202623 [details]
proposed patch against 3.0 maintenance

This patch simply change java and orm version attribute mapping to be 'overridable attribute mappings'. It also updates the appropriate tests.
Comment 6 Neil Hauge CLA 2011-09-02 17:07:13 EDT
    Explain why you believe this is a stop-ship defect. Or, if it is a "hotbug" (requested by an adopter) please document it as such. 

This is a regression, and is very high priority given that it is an invalid error message.

    Is there a work-around? If so, why do you believe the work-around is insufficient? 

There is a workaround (see comment 4) but it removes this broad error message which may cause false validation results for other attribute override situations where there should be an error.

    How has the fix been tested? Is there a test case attached to the bugzilla record? Has a JUnit Test been added? 

Karen has tested the patch, units tests have been run and updated as necessary.

    Give a brief technical overview. Who has reviewed this fix? 

See comment 5.  I have reviewed the fix.

    What is the risk associated with this fix? 

Risk is low.  Fix is small and well understood.
Comment 7 Chuck Bridgham CLA 2011-09-07 13:56:37 EDT
Patch looks good - thanks
Comment 8 David Williams CLA 2011-09-07 14:03:02 EDT
a "normal" level of severity? But, does look important to fix. 

Tip for future: its easier to review if patch the "main" code is separate from the test code. At first I was thinking "what a huge change" ... but at least some is for test code only. Guess there's pros and cons both ways. 

Looks pretty boiler plate, so I think it safe.
Comment 9 Karen Butzke CLA 2011-09-07 16:51:29 EDT
committed this patch to maintenance and head
Comment 10 Jolene Moffitt CLA 2011-09-20 12:04:45 EDT
Verified in Build M-3.3.1-20110915193224 

Verified the validation error does not exist when you create a JPA project with the attached two entities.  See the link to view test steps for verification.  http://wiki.eclipse.org/Dali_3.0.1