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

Bug 341929

Summary: ClassCastException when calling EntitiyManager.getCriteriaBuilder()
Product: z_Archived Reporter: Missing name <deppdepp>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P2 CC: deppdepp, michael.f.obrien, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
URL: http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_42:_20090709:_IdentifiableType.supertype_-_what_do_top-level_types_set_it_to
Whiteboard:
Bug Depends on: 266912    
Bug Blocks:    

Description Missing name CLA 2011-04-05 11:12:40 EDT
Build Identifier: 2.1.2 and 2.2.0

When calling EntitiyManager.getCriteriaBuilder() I get a ClassCastException:
java.lang.ClassCastException: org.eclipse.persistence.internal.jpa.metamodel.EmbeddableTyp eImpl cannot be cast to javax.persistence.metamodel.IdentifiableType

I tried EclipseLink 2.1.2 and 2.2.0, both the same behaviour.

I also opened a thread in the forum:
http://www.eclipse.org/forums/index.php?t=msg&goto=662474&S=68b3ab530f3d4764ae9fdd309273ce16

It may be possible that an entity is deriving from an embeddable - I haven't verified that yet.
(Since I have a lot of entities I can't post the whole model here, sorry.)

Anyway, the stacktraces (see forum) aren't very helpful.

Reproducible: Always

Steps to Reproduce:
1. emf = Persistence.createEntityManagerFactory(persistenceUnit, jpaProperties);
2. em = emf.createEntityManager();
3. mm = em.getMetamodel();  OR  cb = em.getCriteriaBuilder();
-> ClassCastException
Comment 1 Tom Ware CLA 2011-04-06 09:37:07 EDT
Please post any information you can about the model.  If we are unable to  recreate, we will have to close this bug.
Comment 2 Michael OBrien CLA 2011-04-06 11:45:18 EDT
>A MappedSuperclass or Entity (Identifiable Types) cannot inherit from an Embeddable (a Managed Type)
It seems that the superclass in the call below also needs to be checked with isIdentifiableType()

>MetamodelImpl.initialize():429 - 2.3 trunk
        Class superclass = aClass.getSuperclass();
        // explicitly set the superType to null (just in case it is initialized to a non-null value in a constructor)
        IdentifiableType<?> identifiableTypeSuperclass = null;
        if(potentialIdentifiableType.isIdentifiableType() && superclass != ClassConstants.OBJECT) {
            // Get the Entity or MappedSuperclass
            // A hierarchy of Entity --> Entity or Entity --> MappedSuperclass will be found
>            identifiableTypeSuperclass = (IdentifiableType<?>)managedTypes.get(superclass);

The above code requires extra exception handling code attached, and should be added to DI 42
http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_42:_20090709:_IdentifiableType.supertype_-_what_do_top-level_types_set_it_to
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:21:10 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink