Bug 341929 - ClassCastException when calling EntitiyManager.getCriteriaBuilder()
Summary: ClassCastException when calling EntitiyManager.getCriteriaBuilder()
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P2 normal (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: 266912
Blocks:
  Show dependency tree
 
Reported: 2011-04-05 11:12 EDT by Missing name CLA
Modified: 2022-06-09 10:21 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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