Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » InstantiationException due to abstract Entity(InstantiationException due to abstract Entity)
InstantiationException due to abstract Entity [message #661724] Sat, 26 March 2011 17:27 Go to next message
Dave M is currently offline Dave M
Messages: 20
Registered: July 2009
Junior Member
== Context ==

* EclipseLink JPA (patched/upgraded to JPA 2.0 support) running in
WebLogic 10.3.4.
* eclipselink.ddl-generation is set to drop-and-create-tables

== Description of Problem ==

I have an abstract class, let's call it MyAbstractEntity, that is annotated
with @Entity. It's part of a framework, and is used optionally, so it may
not have any concrete subclasses in a particular JPA application, and in
this case it does not.

The exception shown below is thrown when an EntityManager is created.

The class MyAbstractEntity does, in fact, have a public no-arg constructor.
The root exception is obviously java.lang.Instantiation exception,
which is thrown when an attempt is made to instantiate an interface or
abstract class, so I assume that's what's happening in this case.

The class in question nees to be an Entity, as opposed to a MappedSuperclass,
because it is the target of queries.

== Question ==

I think I'm just missing something simple here. Does Eclipselink attempt
to instantiate every class that is annotated with @Entity during its
initialization process? If so, what do you/we do about abstract classes?
Or is there some other reason for an exception like the one below?

== Stack Trace ==

[EL Severe]: 2011-03-26 10:41:50.5--ServerSession(14356349)--Thread(Thread[[ACTIVE] ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Local Exception Stack:
Exception [EclipseLink-0] (Eclipse Persistence Services - 2.1.2.v20101206-r8635): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions:
---------------------------------------------------------

Exception [EclipseLink-34] (Eclipse Persistence Services - 2.1.2.v20101206-r8635): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: This class does not define a public default constructor, or the constructor raised an exception.
Internal Exception: java.lang.InstantiationException
Descriptor: RelationalDescriptor(com.myco.MyAbstractEntity --> [DatabaseTable(MY_ABSTRACT_ENTITY)])

Runtime Exceptions:
---------------------------------------------------------

        at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:471)
        at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
        at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:666)
        at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:628)
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:230)
        at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:389)
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:164)
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:221)
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:209)
        at org.springframework.orm.jpa.JpaTransactionManager.createEntityManagerForTransaction(JpaTransactionManager.java:400)
        at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:321)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)


Thanks,

Dave
Re: InstantiationException due to abstract Entity [message #661984 is a reply to message #661724] Mon, 28 March 2011 17:49 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Because the class has no subclasses, EclipseLink is assuming it is concrete, and validating that it has a constructor.

Please log a bug, we should not do this if the class is abstract.

You can use a SessinCustomizer to disable this check by setting setShouldCheckInstantiationPolicy(false) in the Session's IntegrityChecker.

Or add a constructor or subclass.



James : Wiki : Book : Blog : Twitter
Re: InstantiationException due to abstract Entity [message #662003 is a reply to message #661984] Mon, 28 March 2011 20:08 Go to previous messageGo to next message
Dave M is currently offline Dave M
Messages: 20
Registered: July 2009
Junior Member
Hi James-

Thanks for the feedback. Adding a constructor made no difference.

I am going to try adding a concrete subclass to see what the effect of that is. As mentioned in the post it is an optional part of a framework so, while there is the possibility of there not being concrete subclasses, I would generally expect there to be concrete subclasses of the entity in question.

I will log a bug as you request.

Thanks,

Dave
Re: InstantiationException due to abstract Entity [message #663886 is a reply to message #662003] Wed, 06 April 2011 17:36 Go to previous message
Dave M is currently offline Dave M
Messages: 20
Registered: July 2009
Junior Member
Submitted as Bug 342055.
Previous Topic:Cloning objects in EclipseLink
Next Topic:Problem with dynamic weaving in equinox
Goto Forum:
  


Current Time: Sat Sep 20 22:15:57 GMT 2014

Powered by FUDForum. Page generated in 0.01681 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software