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

Bug 334175

Summary: Wrong PK Identification for inherited entity when using embeddable data object (not ePK) in both subclasses
Product: z_Archived Reporter: Sergey Ponomarev <serggt1>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: CLOSED FIXED QA Contact:
Severity: major    
Priority: P2 CC: eclipselink.orm-inbox, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
project with entities and testcase
none
proposed fix 2.3 stream
none
proposed fix - trunk none

Description Sergey Ponomarev CLA 2011-01-12 16:56:34 EST
Build Identifier: EclipseLink 2.1.1

There is a class hierarchy:
abstract Geozone - CircleGeozone
                 - PolygonGeozone

Both circle and polygon geozones use embeddable object GeoPoint, and it becomes PK for PolygonGeozone for some reason.

Maven project with unit test is included, it passes well on Hibernate.

Reproducible: Always

Steps to Reproduce:
1. lookup for CircleGeozone using find()
2. lookup for PolygonGeozone using find(), it breaks
Comment 1 Sergey Ponomarev CLA 2011-01-12 16:57:33 EST
Created attachment 186684 [details]
project with entities and testcase
Comment 2 Tom Ware CLA 2011-01-26 14:46:48 EST
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
Comment 3 Tom Ware CLA 2011-10-05 15:56:56 EDT
The EclipseLink bug is a result of the way we handle Descriptors for Embeddables.

Initially, a descriptor is created that is shared amoung all embeddables.  At our session initialization time, that descriptor is cloned and the clone is modified with the values that are particular to the mapping that is using it.   The behavior will be different for Embeddables that are part of ElementCollections vs. Embeddables that are used as Embedded.

In the case listed in this bug, an Embeddable is being used both as part of an ElementCollection and directly as an Embedded.  Depending on the initialization order, it will function as one or the other -> yielding different errors in each case.

The case in this bug occurs when the Embedded version is processed first by our processing of the metadata.  In this case, we are treating the dscripor as if it were part of an ElementCollection (last-in wins).  In that case, we treat all the fields as the primary key and as a side effect of some other code, copy those keys to the owning-descriptor.
Comment 4 Tom Ware CLA 2011-10-05 15:57:42 EDT
Workaround is likely to fix the primary key for the owning descriptor post-login.
Comment 5 Tom Ware CLA 2011-10-06 13:59:29 EDT
Created attachment 204701 [details]
proposed fix 2.3 stream
Comment 6 Tom Ware CLA 2011-10-06 14:43:52 EDT
Created attachment 204706 [details]
proposed fix - trunk
Comment 7 Tom Ware CLA 2011-10-06 14:48:20 EDT
The fix makes it so that people that are going to share Embeddables should set the descriptor as aggregate (rather than aggregate collection).  At descriptor clone time, AggregateCollectionMapping will change aggregate descriptors to be aggreateCollection.

Also changed some checks throughout eclispelink to be more specific about what they are testing for to allow easier searching for places where it is relevant whether something is aggregate vs. aggregate colleciton
Comment 8 Tom Ware CLA 2011-10-06 15:34:15 EDT
Fixed in trunk and 2.3 as described above

Reviewed by Andrei Ilitchev

Tested with Core and JPA LRG

Added test to InheritedTestModel
Comment 9 Eclipse Webmaster CLA 2022-06-09 10:28:10 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink