-->
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.  [ 2 posts ] 
Author Message
 Post subject: WrongClassException -- problem with subclass query
PostPosted: Wed Mar 09, 2005 6:23 pm 
Newbie

Joined: Mon Dec 13, 2004 5:56 pm
Posts: 12
Location: Montreal, QC
hello,

I'm going in circles with this class exception -- basically i'm trying to filter out items of a specifc class, using the discriminator value. but its really not working. i havea feeling i'm doing something wrong...

thanks,
sara
===================================================

Hibernate version:

3.0beta4 (reverted when i hit the problem with subqueries in the rc)

Mapping documents:

Code:
<class  name="Term" table="term">
<id name="id" column="id" type="integer">
<generator class="hilo"/>
</id>

<discriminator column="term_type" type="string"/>

<property name="name"
column="name"
type="string"
/>

<property name="termType"
column="term_type"
type="string"
update="false"
insert="false"
/>

<property name="acc"
column="acc"
type="string"
/>

<property name="isObsolete"
column="is_obsolete"
type="integer"
/>

<property name="isRoot"
column="is_root"
type="integer"
/>

<set name="genes" table="term2gene_product" lazy="true" inverse="false">
<key column="term_id"/>
<many-to-many class="ca.mcgill.mcb.bias.hibernate.GO.GeneProduct"
column="gene_product_id"/>
</set>

<set name="parents" table="term2term" lazy="true">
<key column="term2_id"/>
<many-to-many class="ca.mcgill.mcb.bias.hibernate.GO.Term" column="term1_id"/>
</set>

<set name="children" table="term2term" lazy="true">
<key column="term1_id"/>
<many-to-many class="ca.mcgill.mcb.bias.hibernate.GO.Term" column="term2_id"/>
</set>

<subclass name="Component" discriminator-value="component">
<set name="proteinStates">
<key column="componentId"/>
<one-to-many class="ca.mcgill.mcb.bias.hibernate.bio.ProteinDomainState"/>

</set>

<set name="complexes">
<key column="compartmentId"/>
<one-to-many class="ca.mcgill.mcb.bias.hibernate.sig.Complex"/>
</set>
</subclass>

<subclass name="Process" discriminator-value="process">

<set name="interactions" table="Process2ProtProtInteraction"
lazy="true">
<key column="processId"/>
<many-to-many class="ca.mcgill.mcb.bias.hibernate.sig.ProtProtInteraction"
column="interactionId"/>
</set>

</subclass>

<subclass name="Function" discriminator-value="function">
<set name="proteinStates" table="Function2ProteinState" inverse="true">
<key column="functionId"/>
<many-to-many class="ca.mcgill.mcb.bias.hibernate.bio.ProteinDomainState"
column="protStateId"/>
</set>
</subclass>
</class>


Code between sessionFactory.openSession() and session.close():
My session code is abstracted away, but I am using the new AST parser....

Code:

//the method that causes the problem....

public List<Term> getFunctionTerms(Set<Term> terms)
  {
    ArrayList<Term> t=new ArrayList<Term>(terms);
    for(int i=0;i<t.size();i++){
      Term term=t.get(i);
      if(!t.get(i).getTermType().equals("molecular_function")){
        t.remove(i);
       
      }
     
    }
    return t;
   
  }


Full stack trace of any exception that occurs:
org.hibernate.WrongClassException: Object with id: 4173 was not of the specified subclass: ca.mcgill.mcb.bias.hibernate.GO.Term (Discriminator: biological_process)
at org.hibernate.loader.Loader.getInstanceClass(Loader.java:915)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:799)
at org.hibernate.loader.Loader.getRow(Loader.java:730)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:284)
at org.hibernate.loader.Loader.doQuery(Loader.java:378)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:199)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1221)
at org.hibernate.loader.EntityLoader.load(EntityLoader.java:137)
at org.hibernate.loader.EntityLoader.load(EntityLoader.java:123)
at org.hibernate.persister.BasicEntityPersister.load(BasicEntityPersister.java:2397)
at org.hibernate.event.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:376)
at org.hibernate.event.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:357)
at org.hibernate.event.DefaultLoadEventListener.load(DefaultLoadEventListener.java:160)
at org.hibernate.event.DefaultLoadEventListener.load(DefaultLoadEventListener.java:134)
at org.hibernate.event.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:113)
at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:621)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:59)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:80)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:133)
at ca.mcgill.mcb.bias.hibernate.GO.Term$$EnhancerByCGLIB$$5a1aedb9.getTermType(<generated>)
at ca.mcgill.mcb.bias.libraries.geneOntology.PairwiseStatistic.getFunctionTerms(PairwiseStatistic.java:524)
at ca.mcgill.mcb.bias.libraries.geneOntology.PairwiseStatistic.getDistance(PairwiseStatistic.java:511)
at ca.mcgill.mcb.bias.modules.pimp.ERData.getGODistance(ERData.java:538)
at ca.mcgill.mcb.bias.modules.pimp.ERStatistics.printGODistances(ERStatistics.java:139)
at ca.mcgill.mcb.bias.modules.pimp.ERStatistics.main(ERStatistics.java:241)



Name and version of the database you are using:

MySQL

The generated SQL (show_sql=true):
it's a prepared statement:
74322 DEBUG SQL - select term0_.id as id0_, term0_.name as name101_0_, term0_.term_type as term2_101_0_, term0_.acc as acc101_0_, term0_.is_obsolete as is5_101_0_, term0_.is_root as is6_101_0_, term0_.term_type as term2_0_ from term term0_ where term0_.id=?


Debug level Hibernate log excerpt:
74321 DEBUG DefaultLoadEventListener - attempting to resolve: [ca.mcgill.mcb.bias.hibernate.GO.Term#2613]
74321 DEBUG DefaultLoadEventListener - object not resolved in any cache: [ca.mcgill.mcb.bias.hibernate.GO.Term#2613]
74321 DEBUG BasicEntityPersister - Materializing entity: [ca.mcgill.mcb.bias.hibernate.GO.Term#2613]
74322 DEBUG AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
74322 DEBUG SQL - select term0_.id as id0_, term0_.name as name101_0_, term0_.term_type as term2_101_0_, term0_.acc as acc101_0_, term0_.is_obsolete as is5_101_0_, term0_.is_root as is6_101_0_, term0_.term_type as term2_0_ from term term0_ where term0_.id=?
74322 DEBUG AbstractBatcher - preparing statement
74322 DEBUG IntegerType - binding '2613' to parameter: 1
74356 DEBUG AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
74357 DEBUG Loader - processing result set
74357 DEBUG Loader - result set row: 0
74357 DEBUG Loader - result row: EntityKey[ca.mcgill.mcb.bias.hibernate.GO.Term#2613]
74357 DEBUG StringType - returning 'molecular_function' as column: term2_0_
74362 DEBUG AbstractBatcher - about to close ResultSet (open ResultSets: 1, globally: 1)
74363 DEBUG AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
74363 DEBUG AbstractBatcher - closing statement
74364 INFO DefaultLoadEventListener - Error performing load command
org.hibernate.WrongClassException: Object with id: 2613 was not of the specified subclass: ca.mcgill.mcb.bias.hibernate.GO.Term (Discriminator: molecular_function)
at org.hibernate.loader.Loader.getInstanceClass(Loader.java:915)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:799)
at org.hibernate.loader.Loader.getRow(Loader.java:730)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:284)
at org.hibernate.loader.Loader.doQuery(Loader.java:378)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:199)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1221)
at org.hibernate.loader.EntityLoader.load(EntityLoader.java:137)
at org.hibernate.loader.EntityLoader.load(EntityLoader.java:123)
at org.hibernate.persister.BasicEntityPersister.load(BasicEntityPersister.java:2397)
at org.hibernate.event.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:376)
at org.hibernate.event.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:357)
at org.hibernate.event.DefaultLoadEventListener.load(DefaultLoadEventListener.java:160)
at org.hibernate.event.DefaultLoadEventListener.load(DefaultLoadEventListener.java:134)
at org.hibernate.event.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:113)
at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:621)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:59)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:80)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:133)
at ca.mcgill.mcb.bias.hibernate.GO.Term$$EnhancerByCGLIB$$5a1aedb9.getTermType(<generated>)
at ca.mcgill.mcb.bias.libraries.geneOntology.PairwiseStatistic.getFunctionTerms(PairwiseStatistic.java:524)
at ca.mcgill.mcb.bias.libraries.geneOntology.PairwiseStatistic.getDistance(PairwiseStatistic.java:511)
at ca.mcgill.mcb.bias.modules.pimp.ERData.getGODistance(ERData.java:538)
at ca.mcgill.mcb.bias.modules.pimp.ERStatistics.printGODistances(ERStatistics.java:139)
at ca.mcgill.mcb.bias.modules.pimp.ERStatistics.main(ERStatistics.java:241)

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 10, 2005 6:42 pm 
Newbie

Joined: Mon Dec 13, 2004 5:56 pm
Posts: 12
Location: Montreal, QC
I found this same error with yet another method:

Code:
     private int getDBDistanceBetweenTerms(Term t1, Term t2) throws HibernateException
  {
    Integer dist=null;
   
    try{

    Query q=sess.createQuery("select gp.distance from GraphPath gp where (gp.term1=? and gp.term2=?) or (gp.term2=? and gp.term1=?)");

    q.setEntity(0,t1);
    q.setEntity(1,t2);
    q.setEntity(2,t1);
    q.setEntity(3,t2);

    dist=(Integer)q.uniqueResult();
...



This time the stack trace starts at the first 'setEntity'. Why is this happening?

-sara


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

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.