-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: InstantiationException with inconsistent inheritance tables
PostPosted: Tue Oct 16, 2007 11:22 am 
Newbie

Joined: Tue Oct 02, 2007 6:41 am
Posts: 4
Hi,

I have an abstract class PDBElement and two concrete subclasses Residue and Atom which inherits of it.

These are my mapping files:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
   <class name="org.mmb.model.PDBElement" table="PDBElement" abstract="true">
      <id name="pdbElementId">
         <generator class="native"/>
      </id>
      
      <many-to-one name="pdbEntry" class="org.mmb.model.PDBEntry" column="idCode"/>
      
      <property name="model"/>
   </class>
</hibernate-mapping>



Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>   
   <joined-subclass name="org.mmb.model.Atom" extends="org.mmb.model.PDBElement" table="Atom">
      <key column="pdbElementId"/>
      
      <property name="name"/>
      <property name="serial"/>
      <property name="altLoc"/>
      <property name="tempFactor"/>
      <property name="element"/>
      
      <many-to-one name="residue" class="org.mmb.model.Residue" column="residueId"/>
   </joined-subclass>
</hibernate-mapping>



Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>   
   <joined-subclass name="org.mmb.model.Residue" extends="org.mmb.model.PDBElement" table="Residue">
      <key column="pdbElementId"/>
      
      <property name="resName"/>
      <property name="chainId"/>
      <property name="resSeq"/>
      <property name="insertionCode" column="iCode"/>
   </joined-subclass>
</hibernate-mapping>


When the database is consistent with this structure then there is no problem. By consistent I mean that if it exists a row in table PDBElement then it must exist another one in any of the two concrete tables (Residue or Atom). If the database is not consistent (there is a row in PDBElement but there is no concrete instance) I begin to have problems. I know that the point should be to avoid having this inconsistent situation, but the database is accessed for so many applications (some of them out of my own control) and I would need to shield my application of these kind of problems.

For example, I have another entity (PDBEntry) with the following mapping file:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
   <class name="org.mmb.model.PDBEntry" table="entries">
      <id name="idCode" type="string"/>
   
    <set name="simulations" inverse="true">
         <key column="pdbCode"/>         
         <one-to-many class="org.mmb.model.Simulation"/>         
      </set>            
            
      <set name="pdbElements" inverse="true">
         <key column="idCode"/>         
         <one-to-many class="org.mmb.model.PDBElement"/>         
      </set>
      
      <map name="dataSets" table="entries_DataSet">
         <key column="pdbCode" not-null="true"/>         
         <map-key formula="dataSetId" type="string"/>         
         <many-to-many class="org.mmb.model.DataSet" column="dataSetId"/>
      </map>               
      
      <property name="header"/>
      <property name="ascDate"/>
      <property name="compound"/>
      <property name="source"/>
      <property name="autors"/>
      <property name="resolution"/>
      <property name="expType"/>
      <property name="type"/>
      <property name="hetnam"/>      
   </class>
</hibernate-mapping>


When I try to execute the following code:


Code:
...
PDBEntry entry = ...

entry.getPdbElements();
...


where

Code:
public Set<PDBElement> getPdbElements()
{
   return pdbElements;
}


then I get the following stack error:

Code:
     [java] org.hibernate.InstantiationException: Cannot instantiate abstract class or interface: org.mmb.model.PDBElement
     [java]    at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:79)
     [java]    at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:106)
     [java]    at org.hibernate.tuple.AbstractEntityTuplizer.instantiate(AbstractEntityTuplizer.java:344)
     [java]    at org.hibernate.persister.entity.AbstractEntityPersister.instantiate(AbstractEntityPersister.java:3272)
     [java]    at org.hibernate.impl.SessionImpl.instantiate(SessionImpl.java:1239)
     [java]    at org.hibernate.impl.SessionImpl.instantiate(SessionImpl.java:1228)
     [java]    at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1291)
     [java]    at org.hibernate.loader.Loader.getRow(Loader.java:1197)
     [java]    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:569)
     [java]    at org.hibernate.loader.Loader.doQuery(Loader.java:689)
     [java]    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
     [java]    at org.hibernate.loader.Loader.loadCollection(Loader.java:1919)
     [java]    at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
     [java]    at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:520)
     [java]    at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
     [java]    at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1676)
     [java]    at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
     [java]    at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
     [java]    at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:138)
     [java]    at org.mmb.model.database.DatabaseConnector.deletePDBElementsByPDBId(DatabaseConnector.java:430)
     [java]    at org.mmb.model.database.PDBParserHelper.startElement(PDBParserHelper.java:136)
     [java]    at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
     [java]    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
     [java]    at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
     [java]    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
     [java]    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
     [java]    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
     [java]    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
     [java]    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
     [java]    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
     [java]    at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
     [java]    at javax.xml.parsers.SAXParser.parse(SAXParser.java:198)
     [java]    at org.mmb.model.database.PDBParser.populatePDBElements(PDBParser.java:190)
     [java]    at org.mmb.model.database.PDBParser.main(PDBParser.java:260)


Any idea to solve the problem? I've tried some things but I got no success and I'm beginning to get crazy :-P

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.