Community
Participate
Working Groups
Build Identifier: EclipseLink 2.0.0.v20091127-r5931 When I use generated canonical metamodel I get "IllegalArgumentException: The type [null] is not the expected [ManagedType] for the key class [class model.Base]" I have: public abstract class Base { public String exampleMethod(Object o) { return "test: " + o.toString(); } } @Entity public class Customer extends Base { private static final long serialVersionUID = 1L; @Id private Integer id; private String name; public Customer() { } ... // getters/setters } code using these classes: EntityManagerFactory factory = Persistence.createEntityManagerFactory( "testunit" ); EntityManager em = factory.createEntityManager(); em.getTransaction().begin(); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Customer> cq = cb.createQuery( Customer.class ); Root<Customer> c = cq.from( Customer.class ); cq.select( c ).where( cb.equal( c.get( Customer_.id ), new Integer(1) ) ); List<Customer> customers = em.createQuery( cq ).getResultList(); for( Customer customer: customers ) { System.out.println( customer.getName() ); } em.getTransaction().commit(); em.close(); stack trace: Exception in thread "main" javax.persistence.PersistenceException: java.lang.IllegalArgumentException: The type [null] is not the expected [ManagedType] for the key class [class model.Base]. at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:392) at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:151) at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:207) at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:195) at main.Start.main(Start.java:20) Caused by: java.lang.IllegalArgumentException: The type [null] is not the expected [ManagedType] for the key class [class model.Base]. at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.managedType(MetamodelImpl.java:424) at org.eclipse.persistence.internal.jpa.metamodel.ManagedTypeImpl.getManagedSuperType(ManagedTypeImpl.java:755) at org.eclipse.persistence.internal.jpa.metamodel.ManagedTypeImpl.isAttributeDeclaredOnlyInLeafType(ManagedTypeImpl.java:1051) at org.eclipse.persistence.internal.jpa.metamodel.ManagedTypeImpl.isAttributeDeclaredOnlyInLeafType(ManagedTypeImpl.java:999) at org.eclipse.persistence.internal.jpa.metamodel.ManagedTypeImpl.getDeclaredAttributes(ManagedTypeImpl.java:314) at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.initializeCanonicalMetamodel(EntityManagerSetupImpl.java:1961) at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.getMetamodel(EntityManagerSetupImpl.java:1941) at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:385) ... 4 more Reproducible: Always Steps to Reproduce: 1. see above 2. 3.
Setting target and priority. See the following page for a description of the meanings of these values: http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
*** Bug 303722 has been marked as a duplicate of this bug. ***
I encountered the same problem but it is not always reproducible. Some other info: Eclipse-Link 2.2.0-SNAPSHOT JPA standalone (without JEE container, JSE app)
>assigning to 2.2 for investigation - we have 3 community votes
>We have a similar model in the JPA test suite under Position (concrete non-entity, non-embeddable, non-mappedSuperclass) +--GalacticPosition (@Entity using @Inheritance(strategy=JOINED) and @Access(AccessType.FIELD) see http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#Mapped_Superclass_Test_Model The following call to the dynamic (non-canonical) metamodel API returns a BasicType (POJO or java class) Type postionNonEntity = ((MetamodelImpl)metamodel).getType(Position.class); postionNonEntity BasicTypeImpl<X> (id=155) javaClass Class<T> (org.eclipse.persistence.testing.models.jpa.metamodel.Position) (id=113) >Normally you would annotate the non-entity class as a @MappedSuperclass as we do in the hierarchy Person ( concrete @MappedSuperclass) +-- Corporation (abstract @MappedSuperclass) +-- Manufacturer (concrete @Entity) >In both case we do not get the IllegalArgumentException - I will need to run canonical generation and get a full reproduction >However, if you wish to use the Base in persistence query or use of properties (although there currently are none) - you must annotate the Base class with @MappedSuperclass
I solved this problem. I had in classpath two persistence unit with the same name (the second one was a test configuration and without all entity classes). That means, no bug in EclipseLink. Appling the dinamic weaving has immediately detected the presence of a second persistence-unit with the same name.
>Correction: this type of inheritance object is a Transient calss See page 303 Listing 10-28: Entity Inheriting from a Transient Superclass in "Pro JPA 2: Mastering the Java Persistence API " http://books.google.com/books?id=j84hdeHH2PYC&printsec=frontcover&dq=pro+ejb+3&source=gbs_similarbooks_s&cad=1#v=onepage&q=pro%20ejb%203&f=false Transient class fields are inherited but not persisted (as in MappedSuperclass) Both Transient and MappedSuperclass fields cannot be targets of relationships or queried on. >However, Transient support must still be verified here for canonical generation
>This Transient root of an Entity issue was fixed in SVN rev# 7444 (2 June 2010 in EclipseLink 2.1) for bug# 315287 http://fisheye2.atlassian.com/changelog/eclipselink/?cs=7444 >I forgot that I fixed this 50 days ago (if you still experience the issue - we can reopen the bug) Fix: We were not returning correctly when the superType of a ManagedType was a BasicType (Transient) >This was design issue 103 for enhancement bug# 266912 http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_103:_20100601:_315287:_Handle_BasicType_as_inheritance_root_for_ManagedTypes
Created attachment 174892 [details] SVN rev# 7444 - handle BasicType as Transient root of Entity
*** This bug has been marked as a duplicate of bug 315287 ***
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink