This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 302606 - JPA: IllegalArgumentException when using canonical metamodel and non-entity (Transient) superclass of entity class
Summary: JPA: IllegalArgumentException when using canonical metamodel and non-entity (...
Status: CLOSED DUPLICATE of bug 315287
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P2 major with 3 votes (vote)
Target Milestone: ---   Edit
Assignee: Michael OBrien CLA
QA Contact:
URL: http://wiki.eclipse.org/EclipseLink/D...
Whiteboard:
Keywords:
: 303722 (view as bug list)
Depends on: 266912 294811
Blocks: 315408 338837
  Show dependency tree
 
Reported: 2010-02-11 12:19 EST by tomt258 CLA
Modified: 2022-06-09 10:07 EDT (History)
5 users (show)

See Also:


Attachments
SVN rev# 7444 - handle BasicType as Transient root of Entity (8.11 KB, patch)
2010-07-21 14:00 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 tomt258 CLA 2010-02-11 12:19:26 EST
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.
Comment 1 Tom Ware CLA 2010-03-02 11:40:04 EST
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
Comment 2 Janne Kytömäki CLA 2010-03-08 07:53:00 EST
*** Bug 303722 has been marked as a duplicate of this bug. ***
Comment 3 Costantino Cerbo CLA 2010-07-20 18:57:08 EDT
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)
Comment 4 Michael OBrien CLA 2010-07-21 09:26:34 EDT
>assigning to 2.2 for investigation - we have 3 community votes
Comment 5 Michael OBrien CLA 2010-07-21 10:00:13 EDT
>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
Comment 6 Costantino Cerbo CLA 2010-07-21 10:16:15 EDT
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.
Comment 7 Michael OBrien CLA 2010-07-21 10:39:56 EDT
>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
Comment 8 Michael OBrien CLA 2010-07-21 13:58:06 EDT
>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
Comment 9 Michael OBrien CLA 2010-07-21 14:00:48 EDT
Created attachment 174892 [details]
SVN rev# 7444 - handle BasicType as Transient root of Entity
Comment 10 Michael OBrien CLA 2010-07-21 14:05:21 EDT

*** This bug has been marked as a duplicate of bug 315287 ***
Comment 11 Eclipse Webmaster CLA 2022-06-09 10:07:56 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink