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

Bug 314906

Summary: JPA2: PluralAttribute.getJavaType returns element type instead of collection type
Product: z_Archived Reporter: Roger Suen <rogersuen>
Component: EclipselinkAssignee: Michael OBrien <michael.f.obrien>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P1 CC: michael.f.obrien, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
URL: http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_104:_20100614:_314906:_PluralAttribute.getJavaType_returns_elementType_instead_of_Collection_Type
Whiteboard:
Bug Depends on: 266912    
Bug Blocks: 289487    
Attachments:
Description Flags
314906 PluralAttribute.getJavaType() now returns collection Java type not elementType none

Description Roger Suen CLA 2010-05-28 12:09:50 EDT
Build Identifier: 

In eclipselink implementation of JPA 2.0 metamodel API, PluralAttribute.getJavaType() returns the element type instead of the collection type. Here's the snippet:
    
org.eclipse.persistence.internal.jpa.metamodel.PluralAttributeImpl.java:

   /**
     *  Return the Java type of the represented attribute.
     *  @return Java type
     */
    @Override
    public Class<C> getJavaType() {
        return (Class<C>)elementType.getJavaType();
    }

Is this what the specification means, or just a bug? I have checked the source code of hibernate, they choose to return the collection type from the method. I think this make sence because for a PluralAttribute, we have getElementType method there.

I'm working on eclipselink-2.0.2.v20100323-r6872

Reproducible: Always
Comment 1 Tom Ware CLA 2010-06-07 14:38:09 EDT
Setting target and priority.  See the following page for details of the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
Comment 2 Michael OBrien CLA 2010-06-14 09:59:59 EDT
>I will check with open design issues in the base bug# 266912
Comment 3 Michael OBrien CLA 2010-06-14 10:32:33 EDT
>This is a bug, the return class is of type C which is not the element type of the collection V

>in
public abstract class PluralAttributeImpl<X, C, V> extends AttributeImpl<X, C> implements PluralAttribute<X, C, V> {
>we should be using 
 * @param <C> The type of the represented collection
>not
 * @param <V> The element type of the represented collection

>The specification does not go into details of the implementation beyond the javadoc for the function above
= "represented attribute"

>However, check the javadoc for getBindableJavaType()
- here we return the elementType
- we will need to discuss what the spec means by elementType and our own internal view of what the elementType instance variable is - and how they differ

     * If the bindable type of the object is <code>PLURAL_ATTRIBUTE</code>,
     * the Java element type is returned. If the bindable type is
    public Class<V> getBindableJavaType() {


>Regression testing will be affected by...
- this will affect functionality of implementor IdentifiableType.getIdType()
- open bug # 289487 [DatabaseField type and typeName different for @BasicMap with @ObjectTypeConverter ] will be affected
https://bugs.eclipse.org/bugs/show_bug.cgi?id=289487
http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_83:_20090914:_MapAttributeImpl.elementType_incorrectly_set_when_.40ObjectTypeConverter_is_present

- Non initialized attributes like
  Collection aList
http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_58:_20090807:_ManagedType_Attribute_Initialization_must_differentiate_between_Collection_and_List

- lazy initialization
http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_59:_20090818:_PluralAttribute.elementType_not_set_for_non-lazy_instantiated_Collection_Attribute
Comment 4 Michael OBrien CLA 2010-06-14 10:38:18 EDT
>This is design issue 104
Comment 6 Michael OBrien CLA 2010-06-14 12:03:45 EDT
Created attachment 171844 [details]
314906 PluralAttribute.getJavaType() now returns collection Java type not elementType

>Add 3 new tests, extended/modified 7 others
>Test results
TEST MODEL NAME: (JUnit test): MetamodelMetamodelTest
Errors: (failures): 0
Fatal Errors: (errors): 0
Passed: 127
Total Tests: 127

TEST MODEL NAME: (JUnit test): Criteria
Errors: (failures): 0
Fatal Errors: (errors): 0
Passed: 141
Total Tests: 141
Comment 7 Michael OBrien CLA 2010-06-14 13:16:59 EDT
>patch posted for eclipselink-dev review
http://dev.eclipse.org/mhonarc/lists/eclipselink-dev/msg04414.html
Comment 8 Michael OBrien CLA 2010-06-14 13:29:11 EDT
>Eclipselink-RT newsgroup posting found - I will reply with final decision shortly.
http://www.eclipse.org/forums/index.php?t=msg&th=169029&start=0&
Comment 9 Michael OBrien CLA 2010-06-14 15:47:24 EDT
>It has been majority decided that we will make this change in the patch
PluralAttribute.getJavaType() will return the Collection interface class (one of Collection.class, Set.class, List.class and Map.class)
Comment 10 Michael OBrien CLA 2010-06-15 17:20:59 EDT
>To summarize: "represented attribute" is the PluralAttribute data structure (Set,List,Map or Collection)
>See SVN Rev# 7618 for Trunk EclipseLink 2.2
http://fisheye2.atlassian.com/changelog/eclipselink/?cs=7618
>EclipseLink 2.1.1 will be packported when the stream opens shortly
Code Reviewed by: Guy Pelletier
JPA 2.0 specification adherence reviewed by: Gordon Yorke, James Sutherland and
Mike Keith
Comment 11 Michael OBrien CLA 2010-06-16 14:33:05 EDT
>P1 is the temporary holder for 2.1.1 queued ports
Comment 12 Eclipse Webmaster CLA 2022-06-09 10:08:28 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink