InstantiationException due to abstract Entity [message #661724] |
Sat, 26 March 2011 17:27 |
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 |
|
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03699 seconds