I have a problem with instantiation of abstract classes. I have a class hierarchy which has an abstract class (AbstractParty) from which several concrete classes inherit.
I thought that if I try to execute an HQL like "from AbstractParty", then Hibernate would instantiate the concrete classes, not try to instantiate the abstract class.
Actually, my application does work with a Hypersonic database, but not when I try to run with an Oracle database. Could an inconsistency in the data in the Oracle database cause the exception I see?
Thanks,
Peter
Hibernate version:
2.1.7
Mapping documents:
Part of the mappings:
<!-- Party. -->
<joined-subclass name="dk.ciber.danbro.party.impl.AbstractParty" table="PARTY">
<key column="ID" />
<!-- Contact. -->
<joined-subclass name="dk.ciber.danbro.party.impl.AbstractContact" table="CONTACT">
<key column="ID" />
<property name="number" column="NUM" type="integer" />
<many-to-one name="category" column="CATEGORY_ID" class="dk.ciber.danbro.catalogue.impl.DefaultCatalogueNode" />
<property name="address" column="ADDRESS" type="string" />
<many-to-one name="zipCity" column="ZIPCITY_ID" class="dk.ciber.danbro.catalogue.impl.DefaultCatalogueNode" />
<property name="telephone" column="TELEPHONE" type="string" />
<property name="telephoneDirect" column="TELEPHONE_DIRECT" type="string" />
<property name="telephoneMobile" column="TELEPHONE_MOBILE" type="string" />
<property name="fax" column="FAX" type="string" />
<property name="emailAddress" column="EMAIL_ADDRESS" type="string" />
<property name="webAddress" column="WEB_ADDRESS" type="string" />
<property name="giroNumber" column="GIRO_NUMBER" type="string" />
<property name="remark" column="REMRK" type="string" />
<!-- Person. -->
<joined-subclass name="dk.ciber.danbro.party.impl.PersonImpl" table="PERSON">
<key column="ID" />
<property name="firstNames" column="FIRSTNAMES" type="string" />
<property name="lastName" column="LASTNAME" type="string" />
<property name="initials" column="INITIALS" type="string" />
<property name="telephonePrivate" column="TELEPHONE_PRIVATE" type="string" />
</joined-subclass>
<!-- Company. -->
<joined-subclass name="dk.ciber.danbro.party.impl.CompanyImpl" table="COMPANY">
<key column="ID" />
<property name="name" column="NAME" type="string" />
<property name="cvrNumber" column="CVR_NUMBER" type="string" />
</joined-subclass>
</joined-subclass> <!-- /contact -->
...
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
org.springframework.orm.hibernate.HibernateSystemException: Cannot instantiate abstract class or interface: dk.ciber.danbro.party.impl.AbstractContact; nested exception is net.sf.hibernate.HibernateException: Cannot instantiate abstract class or interface: dk.ciber.danbro.party.impl.AbstractContact
net.sf.hibernate.HibernateException: Cannot instantiate abstract class or interface: dk.ciber.danbro.party.impl.AbstractContact
at net.sf.hibernate.persister.AbstractEntityPersister.instantiate(AbstractEntityPersister.java:349)
at net.sf.hibernate.impl.SessionImpl.instantiate(SessionImpl.java:1794)
at net.sf.hibernate.impl.SessionImpl.instantiate(SessionImpl.java:1786)
at net.sf.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:581)
at net.sf.hibernate.loader.Loader.getRow(Loader.java:505)
at net.sf.hibernate.loader.Loader.getRowFromResultSet(Loader.java:218)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:285)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:138)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1063)
at net.sf.hibernate.loader.Loader.list(Loader.java:1054)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1554)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:49)
at org.springframework.orm.hibernate.HibernateTemplate$24.doInHibernate(HibernateTemplate.java:620)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:312)
at org.springframework.orm.hibernate.HibernateTemplate.find(HibernateTemplate.java:616)
at dk.ciber.danbro.common.impl.HibernateDao.query(HibernateDao.java:106)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:282)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:155)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:56)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy0.query(Unknown Source)
at dk.ciber.danbro.party.impl.DefaultPartyManager.getParties(DefaultPartyManager.java:41)
at dk.ciber.danbro.party.web.PartyLookupController.generatePartyList(PartyLookupController.java:82)
at dk.ciber.danbro.party.web.PartyLookupController.referenceData(PartyLookupController.java:69)
at org.springframework.web.servlet.mvc.SimpleFormController.referenceData(SimpleFormController.java:165)
at org.springframework.web.servlet.mvc.AbstractFormController.showForm(AbstractFormController.java:432)
at org.springframework.web.servlet.mvc.AbstractFormController.showForm(AbstractFormController.java:409)
at org.springframework.web.servlet.mvc.SimpleFormController.showForm(SimpleFormController.java:191)
at org.springframework.web.servlet.mvc.AbstractFormController.showNewForm(AbstractFormController.java:291)
at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:233)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:128)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:595)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:543)
at org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:390)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:341)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:257)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:184)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:206)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:833)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:732)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:619)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:688)
at java.lang.Thread.run(Unknown Source)
Name and version of the database you are using:
Oracle, 9
The generated SQL (show_sql=true):
select abstractpa0_.ID as ID, decode (abstractpa0_.ID, abstractpa0__4_.ID, 1, abstractpa0__5_.ID, 2, abstractpa0__3_.ID, 3, abstractpa0__6_.ID, 4,0 ) as clazz_, abstractpa0__1_.PARENT_ID as PARENT_ID11_, abstractpa0__3_.NUM as NUM14_, abstractpa0__3_.CATEGORY_ID as CATEGORY3_14_, abstractpa0__3_.ADDRESS as ADDRESS14_, abstractpa0__3_.ZIPCITY_ID as ZIPCITY_ID14_, abstractpa0__3_.TELEPHONE as TELEPHONE14_, abstractpa0__3_.TELEPHONE_DIRECT as TELEPHON7_14_, abstractpa0__3_.TELEPHONE_MOBILE as TELEPHON8_14_, abstractpa0__3_.FAX as FAX14_, abstractpa0__3_.EMAIL_ADDRESS as EMAIL_A10_14_, abstractpa0__3_.WEB_ADDRESS as WEB_ADD11_14_, abstractpa0__3_.GIRO_NUMBER as GIRO_NU12_14_, abstractpa0__3_.REMRK as REMRK14_, abstractpa0__4_.FIRSTNAMES as FIRSTNAMES16_, abstractpa0__4_.LASTNAME as LASTNAME16_, abstractpa0__4_.INITIALS as INITIALS16_, abstractpa0__4_.TELEPHONE_PRIVATE as TELEPHON5_16_, abstractpa0__5_.NAME as NAME18_, abstractpa0__5_.CVR_NUMBER as CVR_NUMBER18_ from PARTY abstractpa0_, NODE abstractpa0__1_, BASE abstractpa0__2_, CONTACT abstractpa0__3_, PERSON abstractpa0__4_, COMPANY abstractpa0__5_, UNIT abstractpa0__6_ where abstractpa0_.ID=abstractpa0__1_.ID and abstractpa0_.ID=abstractpa0__2_.ID and abstractpa0_.ID=abstractpa0__3_.ID(+) and abstractpa0_.ID=abstractpa0__4_.ID(+) and abstractpa0_.ID=abstractpa0__5_.ID(+) and abstractpa0_.ID=abstractpa0__6_.ID(+)
Debug level Hibernate log excerpt:
2005-03-11 14:29:07,078 INFO [dk.ciber.danbro.party.web.PartyLookupController] - <formBackingObject>
2005-03-11 14:29:07,078 DEBUG [net.sf.hibernate.impl.SessionImpl] - <opened session>
2005-03-11 14:29:07,140 DEBUG [net.sf.hibernate.transaction.JDBCTransaction] - <begin>
2005-03-11 14:29:07,140 DEBUG [net.sf.hibernate.transaction.JDBCTransaction] - <current autocommit status:true>
2005-03-11 14:29:07,140 DEBUG [net.sf.hibernate.transaction.JDBCTransaction] - <disabling autocommit>
2005-03-11 14:29:07,140 INFO [dk.ciber.danbro.common.impl.HibernateDao] - <QUERY=from AbstractParty>
2005-03-11 14:29:07,140 DEBUG [net.sf.hibernate.impl.SessionImpl] - <find: from AbstractParty>
2005-03-11 14:29:07,140 DEBUG [net.sf.hibernate.engine.QueryParameters] - <named parameters: {}>
2005-03-11 14:29:07,156 DEBUG [net.sf.hibernate.hql.QueryTranslator] - <compiling query>
2005-03-11 14:29:07,156 DEBUG [net.sf.hibernate.impl.SessionImpl] - <flushing session>
2005-03-11 14:29:07,156 DEBUG [net.sf.hibernate.impl.SessionImpl] - <Flushing entities and processing referenced collections>
2005-03-11 14:29:07,156 DEBUG [net.sf.hibernate.impl.SessionImpl] - <Processing unreferenced collections>
2005-03-11 14:29:07,156 DEBUG [net.sf.hibernate.impl.SessionImpl] - <Scheduling collection removes/(re)creates/updates>
2005-03-11 14:29:07,156 DEBUG [net.sf.hibernate.impl.SessionImpl] - <Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects>
2005-03-11 14:29:07,156 DEBUG [net.sf.hibernate.impl.SessionImpl] - <Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections>
2005-03-11 14:29:07,171 DEBUG [net.sf.hibernate.impl.SessionImpl] - <Dont need to execute flush>
2005-03-11 14:29:07,171 DEBUG [net.sf.hibernate.hql.QueryTranslator] - <HQL: from dk.ciber.danbro.party.impl.AbstractParty>
2005-03-11 14:29:07,171 DEBUG [net.sf.hibernate.hql.QueryTranslator] - <SQL: select abstractpa0_.ID as ID, decode (abstractpa0_.ID, abstractpa0__4_.ID, 1, abstractpa0__5_.ID, 2, abstractpa0__3_.ID, 3, abstractpa0__6_.ID, 4,0 ) as clazz_, abstractpa0__1_.PARENT_ID as PARENT_ID11_, abstractpa0__3_.NUM as NUM14_, abstractpa0__3_.CATEGORY_ID as CATEGORY3_14_, abstractpa0__3_.ADDRESS as ADDRESS14_, abstractpa0__3_.ZIPCITY_ID as ZIPCITY_ID14_, abstractpa0__3_.TELEPHONE as TELEPHONE14_, abstractpa0__3_.TELEPHONE_DIRECT as TELEPHON7_14_, abstractpa0__3_.TELEPHONE_MOBILE as TELEPHON8_14_, abstractpa0__3_.FAX as FAX14_, abstractpa0__3_.EMAIL_ADDRESS as EMAIL_A10_14_, abstractpa0__3_.WEB_ADDRESS as WEB_ADD11_14_, abstractpa0__3_.GIRO_NUMBER as GIRO_NU12_14_, abstractpa0__3_.REMRK as REMRK14_, abstractpa0__4_.FIRSTNAMES as FIRSTNAMES16_, abstractpa0__4_.LASTNAME as LASTNAME16_, abstractpa0__4_.INITIALS as INITIALS16_, abstractpa0__4_.TELEPHONE_PRIVATE as TELEPHON5_16_, abstractpa0__5_.NAME as NAME18_, abstractpa0__5_.CVR_NUMBER as CVR_NUMBER18_ from PARTY abstractpa0_, NODE abstractpa0__1_, BASE abstractpa0__2_, CONTACT abstractpa0__3_, PERSON abstractpa0__4_, COMPANY abstractpa0__5_, UNIT abstractpa0__6_ where abstractpa0_.ID=abstractpa0__1_.ID and abstractpa0_.ID=abstractpa0__2_.ID and abstractpa0_.ID=abstractpa0__3_.ID(+) and abstractpa0_.ID=abstractpa0__4_.ID(+) and abstractpa0_.ID=abstractpa0__5_.ID(+) and abstractpa0_.ID=abstractpa0__6_.ID(+)>
2005-03-11 14:29:07,171 DEBUG [net.sf.hibernate.impl.BatcherImpl] - <about to open: 0 open PreparedStatements, 0 open ResultSets>
2005-03-11 14:29:07,171 DEBUG [net.sf.hibernate.SQL] - <select abstractpa0_.ID as ID, decode (abstractpa0_.ID, abstractpa0__4_.ID, 1, abstractpa0__5_.ID, 2, abstractpa0__3_.ID, 3, abstractpa0__6_.ID, 4,0 ) as clazz_, abstractpa0__1_.PARENT_ID as PARENT_ID11_, abstractpa0__3_.NUM as NUM14_, abstractpa0__3_.CATEGORY_ID as CATEGORY3_14_, abstractpa0__3_.ADDRESS as ADDRESS14_, abstractpa0__3_.ZIPCITY_ID as ZIPCITY_ID14_, abstractpa0__3_.TELEPHONE as TELEPHONE14_, abstractpa0__3_.TELEPHONE_DIRECT as TELEPHON7_14_, abstractpa0__3_.TELEPHONE_MOBILE as TELEPHON8_14_, abstractpa0__3_.FAX as FAX14_, abstractpa0__3_.EMAIL_ADDRESS as EMAIL_A10_14_, abstractpa0__3_.WEB_ADDRESS as WEB_ADD11_14_, abstractpa0__3_.GIRO_NUMBER as GIRO_NU12_14_, abstractpa0__3_.REMRK as REMRK14_, abstractpa0__4_.FIRSTNAMES as FIRSTNAMES16_, abstractpa0__4_.LASTNAME as LASTNAME16_, abstractpa0__4_.INITIALS as INITIALS16_, abstractpa0__4_.TELEPHONE_PRIVATE as TELEPHON5_16_, abstractpa0__5_.NAME as NAME18_, abstractpa0__5_.CVR_NUMBER as CVR_NUMBER18_ from PARTY abstractpa0_, NODE abstractpa0__1_, BASE abstractpa0__2_, CONTACT abstractpa0__3_, PERSON abstractpa0__4_, COMPANY abstractpa0__5_, UNIT abstractpa0__6_ where abstractpa0_.ID=abstractpa0__1_.ID and abstractpa0_.ID=abstractpa0__2_.ID and abstractpa0_.ID=abstractpa0__3_.ID(+) and abstractpa0_.ID=abstractpa0__4_.ID(+) and abstractpa0_.ID=abstractpa0__5_.ID(+) and abstractpa0_.ID=abstractpa0__6_.ID(+)>
Hibernate: select abstractpa0_.ID as ID, decode (abstractpa0_.ID, abstractpa0__4_.ID, 1, abstractpa0__5_.ID, 2, abstractpa0__3_.ID, 3, abstractpa0__6_.ID, 4,0 ) as clazz_, abstractpa0__1_.PARENT_ID as PARENT_ID11_, abstractpa0__3_.NUM as NUM14_, abstractpa0__3_.CATEGORY_ID as CATEGORY3_14_, abstractpa0__3_.ADDRESS as ADDRESS14_, abstractpa0__3_.ZIPCITY_ID as ZIPCITY_ID14_, abstractpa0__3_.TELEPHONE as TELEPHONE14_, abstractpa0__3_.TELEPHONE_DIRECT as TELEPHON7_14_, abstractpa0__3_.TELEPHONE_MOBILE as TELEPHON8_14_, abstractpa0__3_.FAX as FAX14_, abstractpa0__3_.EMAIL_ADDRESS as EMAIL_A10_14_, abstractpa0__3_.WEB_ADDRESS as WEB_ADD11_14_, abstractpa0__3_.GIRO_NUMBER as GIRO_NU12_14_, abstractpa0__3_.REMRK as REMRK14_, abstractpa0__4_.FIRSTNAMES as FIRSTNAMES16_, abstractpa0__4_.LASTNAME as LASTNAME16_, abstractpa0__4_.INITIALS as INITIALS16_, abstractpa0__4_.TELEPHONE_PRIVATE as TELEPHON5_16_, abstractpa0__5_.NAME as NAME18_, abstractpa0__5_.CVR_NUMBER as CVR_NUMBER18_ from PARTY abstractpa0_, NODE abstractpa0__1_, BASE abstractpa0__2_, CONTACT abstractpa0__3_, PERSON abstractpa0__4_, COMPANY abstractpa0__5_, UNIT abstractpa0__6_ where abstractpa0_.ID=abstractpa0__1_.ID and abstractpa0_.ID=abstractpa0__2_.ID and abstractpa0_.ID=abstractpa0__3_.ID(+) and abstractpa0_.ID=abstractpa0__4_.ID(+) and abstractpa0_.ID=abstractpa0__5_.ID(+) and abstractpa0_.ID=abstractpa0__6_.ID(+)
2005-03-11 14:29:07,171 DEBUG [net.sf.hibernate.impl.BatcherImpl] - <preparing statement>
2005-03-11 14:29:07,171 DEBUG [net.sf.hibernate.loader.Loader] - <processing result set>
2005-03-11 14:29:07,171 DEBUG [net.sf.hibernate.type.LongType] - <returning '19' as column: ID>
2005-03-11 14:29:07,171 DEBUG [net.sf.hibernate.loader.Loader] - <result row: 19>
2005-03-11 14:29:07,171 DEBUG [net.sf.hibernate.type.IntegerType] - <returning '3' as column: clazz_>
2005-03-11 14:29:07,171 DEBUG [net.sf.hibernate.impl.BatcherImpl] - <done closing: 0 open PreparedStatements, 0 open ResultSets>
2005-03-11 14:29:07,171 DEBUG [net.sf.hibernate.impl.BatcherImpl] - <closing statement>
2005-03-11 14:29:07,171 DEBUG [net.sf.hibernate.transaction.JDBCTransaction] - <rollback>
2005-03-11 14:29:07,187 DEBUG [net.sf.hibernate.impl.SessionImpl] - <transaction completion>
2005-03-11 14:29:07,187 DEBUG [net.sf.hibernate.transaction.JDBCTransaction] - <re-enabling autocommit>
2005-03-11 14:29:07,187 DEBUG [net.sf.hibernate.impl.SessionImpl] - <closing session>
2005-03-11 14:29:07,187 DEBUG [net.sf.hibernate.impl.SessionImpl] - <disconnecting session>
2005-03-11 14:29:07,187 DEBUG [net.sf.hibernate.impl.SessionImpl] - <transaction completion>
2005-03-11 14:29:07,187 ERROR [org.springframework.web.servlet.DispatcherServlet] - <Could not complete request>
org.springframework.orm.hibernate.HibernateSystemException: Cannot instantiate abstract class or interface: dk.ciber.danbro.party.impl.AbstractContact; nested exception is net.sf.hibernate.HibernateException: Cannot instantiate abstract class or interface: dk.ciber.danbro.party.impl.AbstractContact
|