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

Bug 315287

Summary: JPA: Metamodel initialization fails when non-Entity-non-MappedSuperclass BasicType at root of hierachy
Product: z_Archived Reporter: Michael OBrien <michael.f.obrien>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P2 CC: eclipselink.orm-inbox, tomt258
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
URL: http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_103:_20100601:_315287:_Handle_BasicType_as_inheritance_root_for_ManagedTypes
Whiteboard:
Bug Depends on: 266912    
Bug Blocks: 315408, 248780, 303722, 338837    
Attachments:
Description Flags
Handle BasicType as JPA inheritance superclass of Metamodel ManagedType
none
Handle BasicType as JPA inheritance superclass of Metamodel ManagedType none

Description Michael OBrien CLA 2010-06-01 15:48:19 EDT
>Problem: If we add a plain java class as the root of an inheritance hierarchy - we fail on initialization with an IAException
>The IAE is because we are using .managedType() internally and do not handle a BasicType at the root

>Test model is extended by adding [Gear] at the top
>Gear (non-entity/non-mappedSuperclass plain java class - non-persistable)
  +-----HockeyGear (Abstract Entity) (not cacheable)
         +----- GoalieGear (Concrete MappedSuperclass) --- (no cache entry) 
                 +----- Chest Protector (Concrete Entity) ---- cacheable
                 +----- Pads (Concrete Entity) ---- cacheable


>we fail here
    public <X> ManagedType<X> managedType(Class<X> clazz) {
        Object aType = this.managedTypes.get(clazz);
        // Throw an IAE exception if the returned type is not a ManagedType
        // For any clazz that resolves to a BasicType - use getType(clazz) in implementations when you are expecting a BasicType
        if(null != aType && aType instanceof ManagedType) {
            return (ManagedType<X>) aType;
        } else {
>            throw new IllegalArgumentException(ExceptionLocalization.buildMessage(
                    "metamodel_class_incorrect_type_instance", 
                    new Object[] { clazz, "ManagedType", aType}));
        }
    }

>with
[EL Finest]: ServerSession(17102073)--Thread(Thread[Thread-4,6,main])--Initialization of the metamodel failed during deployment.  Ignoring exception: [The type [null] is not the expected [ManagedType] for the key class [class org.eclipse.persistence.testing.models.jpa.advanced.fetchgroup.Gear].] 

Thread [Thread-4] (Suspended (breakpoint at line 425 in MetamodelImpl))	
	MetamodelImpl.managedType(Class<X>) line: 425	
	EntityTypeImpl<X>(ManagedTypeImpl<X>).getManagedSuperType() line: 761	
	EntityTypeImpl<X>(ManagedTypeImpl<X>).isAttributeDeclaredOnlyInLeafType(String, Attribute) line: 1057	
	MappedSuperclassTypeImpl<X>(ManagedTypeImpl<X>).isAttributeDeclaredOnlyInLeafType(String, Attribute) line: 1083	
	EntityTypeImpl<X>(ManagedTypeImpl<X>).isAttributeDeclaredOnlyInLeafType(String, Attribute) line: 1083	
	EntityTypeImpl<X>(ManagedTypeImpl<X>).isAttributeDeclaredOnlyInLeafType(String) line: 1005	
	EntityTypeImpl<X>(ManagedTypeImpl<X>).getDeclaredAttributes() line: 320	
	EntityManagerSetupImpl.initializeCanonicalMetamodel(Metamodel) line: 2020	
	EntityManagerSetupImpl.getMetamodel() line: 1998	
	EntityManagerSetupImpl.deploy(ClassLoader, Map) line: 398	
	EntityManagerFactoryImpl.getServerSession() line: 157	
	EntityManagerFactoryImpl.createEntityManagerImpl(Map) line: 214	
	EntityManagerFactoryImpl.createEntityManager() line: 202	
	JUnitTestCase.getServerSession() line: 365	
	JUnitTestCase.clearCache() line: 228	
	AdvancedJPAJunitTest.setUp() line: 107	

>using
aSuperType = (ManagedTypeImpl<?>)this.getMetamodel().managedType(aSuperClass);

>we should be using 
aNonManagedSuperType = this.getMetamodel().getType(aSuperClass);
Comment 1 Michael OBrien CLA 2010-06-01 15:50:28 EDT
>blocks main metamodel bug# 266912 (finished)
>blocks cache API bug (because of the pojo root at the extended test model)
Comment 2 Michael OBrien CLA 2010-06-01 15:55:41 EDT
>this breaks all Criteria API users that have a model where an Entity or MappedSuperclass inherit from a BasicType
>predeploy succeeds
>em.getMetamodel() fails
Comment 3 Michael OBrien CLA 2010-06-01 19:51:20 EDT
Created attachment 170725 [details]
Handle BasicType as JPA inheritance superclass of Metamodel ManagedType
Comment 4 Michael OBrien CLA 2010-06-01 23:27:44 EDT
Created attachment 170738 [details]
Handle BasicType as JPA inheritance superclass of Metamodel ManagedType
Comment 5 Michael OBrien CLA 2010-06-02 01:55:18 EDT
>see SVN rev# 7444 with test results
http://fisheye2.atlassian.com/changelog/eclipselink/?cs=7444
Comment 6 Michael OBrien CLA 2010-06-02 11:05:51 EDT
>see additional future expansion of metamodel test model with BasicType inheritance root
http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#Mapped_Superclass_Test_Model
Comment 7 Michael OBrien CLA 2010-07-21 14:05:21 EDT
*** Bug 302606 has been marked as a duplicate of this bug. ***
Comment 8 Eclipse Webmaster CLA 2022-06-09 10:16:18 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 9 Eclipse Webmaster CLA 2022-06-09 10:18:44 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink