-->
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: composite-id class ClassCastException Object->Integer
PostPosted: Wed Dec 01, 2010 7:40 pm 
Newbie

Joined: Tue Jun 22, 2010 11:26 am
Posts: 9
Hi all,

During insertion I have exception:
Quote:
java.lang.ClassCastException: org.phibase.database.schema.GeneNamesId cannot be cast to java.lang.Integer


The values are inserted to the database.

GeneNamesId is related with Gene Name table which is mapped:
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">
<!-- Generated 01-Dec-2010 22:43:46 by Hibernate Tools 3.4.0.Beta1 -->
<hibernate-mapping>
    <class name="org.phibase.database.schema.GeneNames" table="GeneNames">
        <composite-id name="id" class="org.phibase.database.schema.GeneNamesId">
            <key-property name="referenceGeneId" type="int">
                <column name="referenceGeneID" />
            </key-property>
            <key-property name="name" type="string">
                <column name="name" />
            </key-property>
            <key-property name="pragmaDisplay" type="boolean">
                <column name="pragmaDisplay" />
            </key-property>
        </composite-id>
        <many-to-one name="referencePhysicalGene" class="org.phibase.database.schema.ReferencePhysicalGene" update="false" insert="false" fetch="select">
            <column name="referenceGeneID" not-null="true" />
        </many-to-one>
    </class>
</hibernate-mapping>



I am not fluent in hibernate but IMHO it looks correct.

I load the values using save from dao:

Code:
...
   @Transactional
   @Override
   public Integer save(T item) {
      return (Integer) getHibernateTemplate().save(item);
   }
...


Fist I save ReferencePhysicalGene. Than I save to database and method returns gene id. After that I do that:
Code:
      String[] geneNames = { "name1", "name2", "name3", "name4" };

      for (String name : geneNames) {
         try {
            GeneNamesId geneNamesIdObject = new GeneNamesId(refGeneId,
                  name, false);

            GeneNames geneNamesObject = new GeneNames();
            geneNamesObject.setId(geneNamesIdObject);

            geneNamesDAO.save(geneNamesObject);
            session.flush();
         } catch (Exception e) {
            log.error("Error with name: " + name, e);
         }
      }


After each insertion I do flush. IMHO everything is OK. For me it looks like a bug.

Regards,
Jacek


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.