This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 285512 - JPA: QueryBuilder.createQuery should not expect Basic type from Metamodel.type(ManagedClass)
Summary: JPA: QueryBuilder.createQuery should not expect Basic type from Metamodel.typ...
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P2 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL: http://wiki.eclipse.org/EclipseLink/D...
Whiteboard:
Keywords:
Depends on:
Blocks: 249218 266912
  Show dependency tree
 
Reported: 2009-08-03 22:43 EDT by Michael OBrien CLA
Modified: 2022-06-09 10:30 EDT (History)
1 user (show)

See Also:


Attachments
MetamodelImpl.type() handler for null type return (handles both Clazz not found and Basic type lookup) (5.38 KB, patch)
2009-08-04 10:43 EDT, Michael OBrien CLA
no flags Details | Diff
Failures that are fixed by the attached patch for any call to .managedType() where we expect a BasicType back - used to return null - now throws an IAE by spec. (32.53 KB, text/plain)
2009-10-14 14:24 EDT, Michael OBrien CLA
no flags Details
DI 54: Metamodel/Criteria Impl change: throw IAE on any Metamodel.managedType(clazz) call where clazz is wrapped by a BasicType - used to return null - use MetamodelImpl.getType(clazz) instead (11.18 KB, patch)
2009-10-14 14:34 EDT, Michael OBrien CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael OBrien CLA 2009-08-03 22:43:56 EDT
>The following line should only process ManagedType types (which does not include BasicType).
QueryBuilderImpl:51
    public <T> CriteriaQuery<T> createQuery(Class<T> resultClass){
...
            ManagedType type = this.metamodel.type(resultClass);

>see the API function
    /**
     *  Return the metamodel managed type representing the 
     *  entity, mapped superclass, or embeddable class.
     *  @param clazz  the type of the represented managed class
     *  @return the metamodel managed type
     *  @throws IllegalArgumentException if not a managed class
     */
    public <X> ManagedType<X> type(Class<X> clazz) 

>IAE exception handlers for MetamodelImpl are disabled until this fix is in.
Comment 1 Michael OBrien CLA 2009-08-03 23:12:16 EDT
>See the following tests (1 normal, 2 variant (null, BasicType) that expect a managedType, IAE and IAE respectively in MetamodelMetamodelTest:1507

            // test normal path: (subtype = MappedSuperclass)
            expectedIAExceptionThrown = false;            
            try {
                Type<Person> aType = metamodel.type(Person.class);
            } catch (IllegalArgumentException iae) {
                iae.printStackTrace();
                expectedIAExceptionThrown = true;            
            }
            assertFalse(expectedIAExceptionThrown);            
            
            // test variant path: null causes IAE
            expectedIAExceptionThrown = false;            
            try {
                Type<?> aType = metamodel.type(null);
            } catch (IllegalArgumentException iae) {
                //iae.printStackTrace();
                expectedIAExceptionThrown = true;            
            }
            assertTrue(expectedIAExceptionThrown);            

            // test variant path: wrong type (java simple type)
            expectedIAExceptionThrown = false;            
            try {
                Type<?> aType = metamodel.embeddable(Integer.class);
            } catch (IllegalArgumentException iae) {
                //iae.printStackTrace();
                expectedIAExceptionThrown = true;            
            }
            assertTrue(expectedIAExceptionThrown);            
Comment 2 Michael OBrien CLA 2009-08-04 10:43:32 EDT
Created attachment 143398 [details]
MetamodelImpl.type() handler for null type return (handles both Clazz not found and Basic type lookup)

>Handle a null (not found) return differently from a Basic Type return (IAE)

>test results
TEST MODEL NAME: (JUnit test): Criteria
Errors: (failures): 0
Fatal Errors: (errors): 0
Passed: 26
Total Tests: 26

TEST MODEL NAME: (JUnit test): MetamodelTestSuite
Errors: (failures): 0
Fatal Errors: (errors): 0
Passed: 3
Total Tests: 3
Comment 3 Michael OBrien CLA 2009-08-04 11:23:37 EDT
>see rev# 4779

http://fisheye2.atlassian.com/changelog/eclipselink/?cs=4779

Test results (JPA LRG): normal, null and IAE paths in MetamodelMetamodelTest:1504 (with 2 known failures fixed) 
   [junit] Tests run: 1300, Failures: 0, Errors: 0, Time elapsed: 1,467.537 sec 
Comment 4 Peter Krogh CLA 2009-08-26 09:58:17 EDT
Mass update to change fixed in target.
Comment 5 Peter Krogh CLA 2009-08-26 10:00:45 EDT
Mass update to change fixed in target.
Comment 6 Peter Krogh CLA 2009-08-26 10:06:03 EDT
Mass update to change fixed in target.
Comment 7 Peter Krogh CLA 2009-08-26 10:07:55 EDT
Mass update to change fixed in target.
Comment 8 Michael OBrien CLA 2009-10-09 15:24:27 EDT
>Note: The function name has changed in the final PFD for the Type interface
From
public <X> ManagedType<X> type(Class<X> clazz)
To
public <X> ManagedType<X> managedType(Class<X> clazz)
Comment 9 Michael OBrien CLA 2009-10-14 13:38:25 EDT
>During a pass through the code - I have decided that the specification is clear - all non-ManagedType clazz parameters should throw an IAE - even null.
The function needs to be reverted back to it's original state - not that it has been renamed .managedType() and its' usage in the Criteria tests should be modified to getType().
I discussed this with Chris.
Comment 10 Michael OBrien CLA 2009-10-14 14:19:51 EDT
>There is a secondary issue to the fix.  In the ''Metamodel'' interface there is no specification function that will return a ''Type'' - the implementation classes will need to be used in this case.

>see reopened design issue 54
http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_54:_20090803:_Metamodel.type.28Clazz.29_should_differentiate_between_null_and_BasicType

CriteriaQueryImpl.java:118
    public CriteriaQuery<T> select(Selection<? extends T> selection) {
      // From:
      ManagedType type = this.metamodel.managedType(this.queryType);
      // To:
      TypeImpl type = ((MetamodelImpl)this.metamodel).getType(this.queryType);

>Test results
>With Metamodel change and no Metamodel-test/Criteria-impl change
TEST MODEL NAME: (JUnit test): test_MetamodelFullImplementation(org.eclipse.persistence.testing.tests.jpa.metamodel.MetamodelMetamodelTest)
Errors: (failures): 1
Fatal Errors: (errors): 0
Passed: 0
Total Tests: 1
TEST NAME: test_MetamodelFullImplementation(org.eclipse.persistence.testing.tests.jpa.metamodel.MetamodelMetamodelTest)
RESULT:      Error (failure)
junit.framework.AssertionFailedError: IllegalArgumentException not expected on Metamodel.managedType(Integer.class)
	at junit.framework.Assert.fail(Assert.java:47)

TEST MODEL NAME: (JUnit test): Criteria
Errors: (failures): 0
Fatal Errors: (errors): 15
Passed: 104
Total Tests: 119

>With Metamodel change and one of the Criteria changes (fixes 12 of the 15 issues)
TEST MODEL NAME: (JUnit test): Criteria
Errors: (failures): 0
Fatal Errors: (errors): 3
Passed: 116
Total Tests: 119
Comment 11 Michael OBrien CLA 2009-10-14 14:24:23 EDT
Created attachment 149571 [details]
Failures that are fixed by the attached patch for any call to .managedType() where we expect a BasicType back - used to return null - now throws an IAE by spec.
Comment 12 Michael OBrien CLA 2009-10-14 14:34:22 EDT
Created attachment 149572 [details]
DI 54: Metamodel/Criteria Impl change: throw IAE on any Metamodel.managedType(clazz) call where clazz is wrapped by a BasicType - used to return null - use MetamodelImpl.getType(clazz) instead
Comment 13 Michael OBrien CLA 2009-10-14 14:35:05 EDT
>test results with patch change on 5536
TEST MODEL NAME: (JUnit test): Criteria
Errors: (failures): 0
Fatal Errors: (errors): 0
Passed: 119
Total Tests: 119

TEST MODEL NAME: (JUnit test): Metamodel
Errors: (failures): 0
Fatal Errors: (errors): 0
Passed: 10
Total Tests: 10
Comment 14 Michael OBrien CLA 2009-10-14 15:08:49 EDT
>In review
Comment 15 Michael OBrien CLA 2009-10-14 16:09:45 EDT
>Reviewed by Gordon - see SVN rev# 5540
http://fisheye2.atlassian.com/changelog/eclipselink/?cs=5540
Test results (JPA LRG) off 5536 
   [junit] Tests run: 1423, Failures: 0, Errors: 0, Time elapsed: 1,162.806 sec
Comment 16 Eclipse Webmaster CLA 2022-06-09 10:30:34 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink