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

Bug 324406

Summary: Wrong Index in ReportItem when @Embeddable Objects are used in ReportQuery
Product: z_Archived Reporter: thomas.spiegl
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: eclipselink.orm-inbox, peter.krogh, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: submitted_patch
Attachments:
Description Flags
Patch peter.krogh: iplog+

Description thomas.spiegl CLA 2010-09-03 08:35:49 EDT
Build Identifier: 2.2.0

If an AggregateObjectMapping is part of the ReportQueryResult then ReportItem.resultIndex may be wrong. See Steps to Reproduce ...


Fix:
ExpressionQueryMechanism.java
replace: line 593
++itemOffset; //only a single attribute can be selected
by:

if (item.getMapping() instanceof AggregateObjectMapping) {
                        itemOffset += item.getMapping().getFields().size(); // Aggregate object may consist out of 1..n fields
                    } else {
                        ++itemOffset; //only a single attribute can be selected
                    }

Reproducible: Always

Steps to Reproduce:
Example:  

1. create @Embeddable class Money { String currency; BigDecimal value; }
2. create @Entity Item {Long id; Money money; String itemNumber; }
3. execute Query: select new QueryObject(i.id, i.money, i.itemNumber) from Items i

Error:
ReportItem.resultIndex = 2 for ResultItem i.itemNumber, should be 4 as Money has 2 fields
Comment 1 thomas.spiegl CLA 2010-09-03 08:38:50 EDT
Created attachment 178138 [details]
Patch
Comment 2 Tom Ware CLA 2010-09-13 15:00:01 EDT
Investigating submitted patch.
Comment 3 Tom Ware CLA 2010-09-14 10:20:03 EDT
Added fix with minor update.

Added test to EntityManagerJunitTestSuite

Tested with JPA LRG

Reviewed by Tom Ware - reviewed user-submitted fix
Comment 4 Peter Krogh CLA 2010-12-08 14:33:34 EST
moving ipLog flag to patch
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:30:41 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink