-->
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: ClassCastException with one-to-many joined using non-PK cols
PostPosted: Wed Sep 20, 2006 3:34 am 
Newbie

Joined: Mon Sep 11, 2006 11:13 am
Posts: 3
Location: Germany
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.1

Mapping documents: pls see below for code

Code between sessionFactory.openSession() and session.close():

private void findT_BASKET() {

try {
Session session1 = sessFactory.openSession();
Transaction tx1 = session1.beginTransaction();

BigDecimal id = new BigDecimal(6382682);
T_BASKET _idObj = new T_BASKET();
_idObj.setInternalid( id );

T_BASKET b1 = (T_BASKET) session1.get( "db.T_BASKET", _idObj );
logger.debug("findById_T_BASKET : " + b1);
tx1.commit();
}
catch ( Exception ex1 ) {
ex1.printStackTrace();
}
finally {
}

}


Full stack trace of any exception that occurs:
[java] Fetching entity: [com.ted.Persistence.model.T_BASKET#component[internalid]{internalid=6382682}]
[java] loading entity: [com.ted.Persistence.model.T_BASKET#component[internalid]{internalid=6382682}]
[java] about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
[java] opening JDBC connection
[java] select t_basket0_.INTERNALID as INTERNALID2_0_, t_basket0_.NETTINGNUMBER as NETTINGN2_2_0_, t_basket0_.TRADE
DATE as TRADEDATE2_0_, t_basket0_.WKN as WKN2_0_, t_basket0_.ISIN as ISIN2_0_, t_basket0_.RIC as RIC2_0_ from T_BASKET t
_basket0_ where t_basket0_.INTERNALID=?
[java] Hibernate: select t_basket0_.INTERNALID as INTERNALID2_0_, t_basket0_.NETTINGNUMBER as NETTINGN2_2_0_, t_bas
ket0_.TRADEDATE as TRADEDATE2_0_, t_basket0_.WKN as WKN2_0_, t_basket0_.ISIN as ISIN2_0_, t_basket0_.RIC as RIC2_0_ from
T_BASKET t_basket0_ where t_basket0_.INTERNALID=?
[java] preparing statement
[java] binding '6382682' to parameter: 1
[java] about to open ResultSet (open ResultSets: 0, globally: 0)
[java] processing result set
[java] result set row: 0
[java] result row: EntityKey[com.ted.Persistence.model.T_BASKET#component[internalid]{internalid=6382682}]
[java] Initializing object from ResultSet: [com.ted.Persistence.model.T_BASKET#component[internalid]{internalid=638
2682}]
[java] Hydrating entity: [com.ted.Persistence.model.T_BASKET#component[internalid]{internalid=6382682}]
[java] returning '5870370' as column: NETTINGN2_2_0_
[java] returning '2006-09-19 11:35:45' as column: TRADEDATE2_0_
[java] returning '593393' as column: WKN2_0_
[java] returning 'DE0005933931' as column: ISIN2_0_
[java] returning 'GDAXIEX.DE' as column: RIC2_0_
[java] done processing result set (1 rows)
[java] about to close ResultSet (open ResultSets: 1, globally: 1)
[java] about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
[java] closing statement
[java] total objects hydrated: 1
[java] resolving associations for [com.ted.Persistence.model.T_BASKET#component[internalid]{internalid=6382682}]
[java] after autocommit
[java] transaction completed on session with on_close connection release mode; be sure to close the session to rele
ase JDBC resources!
[java] after transaction completion
[java] java.lang.ClassCastException: java.math.BigDecimal
[java] T_BASKETDaoHibernate.findById failed : java.math.BigDecimal
[java] at org.hibernate.type.ComponentType.toLoggableString(ComponentType.java:329)
[java] at org.hibernate.pretty.MessageHelper.collectionInfoString(MessageHelper.java:284)
[java] at org.hibernate.engine.CollectionLoadContext.getLoadingCollection(CollectionLoadContext.java:141)
[java] at org.hibernate.type.CollectionType.getCollection(CollectionType.java:488)
[java] at org.hibernate.type.CollectionType.resolveKey(CollectionType.java:341)
[java] at org.hibernate.type.CollectionType.resolve(CollectionType.java:335)
[java] at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116)
[java] at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
[java] at org.hibernate.loader.Loader.doQuery(Loader.java:717)
[java] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
[java] at org.hibernate.loader.Loader.loadEntity(Loader.java:1785)
[java] at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:47)
[java] at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:41)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2730)
[java] at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365
)
[java] at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346)
[java] at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123)
[java] at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:177)
[java] at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
[java] at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862)
[java] at org.hibernate.impl.SessionImpl.get(SessionImpl.java:799)
[java] at com.ted.Persistence.dao.hibernate.T_BASKETDaoHibernate.findById(T_BASKETDaoHibernate.java:101)
[java] at com.ted.Persistence.service.T_BASKETServiceImpl.findById(T_BASKETServiceImpl.java:53)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:324)
[java] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:287)
[java] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:165)
[java] at $Proxy1.findById(Unknown Source)
[java] at com.ted.Persistence.main.TedPersistenceMain.findById_T_BASKET(TedPersistenceMain.java:270)
[java] at com.ted.Persistence.main.TedPersistenceMain.main(TedPersistenceMain.java:56)

Name and version of the database you are using: Oracle 9.2.0.7.0

The generated SQL (show_sql=true): see trace above

Debug level Hibernate log excerpt: see trace above



===============================================
Description : Implementation of one-to-many association, joining with one column. The join column is not the primary key of either table.

--------------------------------------------------------------------------------------
mapping / POJOs
--------------------------------------------------------------------------------------

Code:
<hibernate-mapping>

   <class name="db.T_BASKET" table="T_BASKET">

      <composite-id>
         <key-property name="internalid" column="INTERNALID" type="big_decimal"/>
      </composite-id>
      <property name="nettingnumber" column="NETTINGNUMBER" type="big_decimal"/>
      <property name="tradedate" column="TRADEDATE" type="calendar"/>
      <property name="wkn" column="WKN" type="string"/>
      <property name="isin" column="ISIN" type="string"/>
      <property name="ric" column="RIC" type="string"/>
      <set name="basketNettings" table="T_NETTINGS" inverse="false" lazy="false">
         <key property-ref="nettingnumber">
            <column name="NETTINGNUMBER"/>
         </key>
         <one-to-many class="db.T_NETTINGS"/>
      </set>
   </class>

</hibernate-mapping>


--------------------------------------------------------------------------------------
Code:
<hibernate-mapping>

   <class name="db.T_NETTINGS" table="T_NETTINGS">

      <composite-id>
         <key-property name="referencenbr" column="REFERENCENBR" type="string"/>
      </composite-id>
      <property name="nettingnumber" column="NETTINGNUMBER" type="big_decimal"/>
      <property name="book" column="BOOK" type="string"/>
      <property name="buysell" column="BUYSELL" type="string"/>
      <property name="nominal" column="NOMINAL" type="big_decimal"/>
      <property name="price" column="PRICE" type="big_decimal"/>
      <property name="priceccy" column="PRICECCY" type="string"/>
   </class>

</hibernate-mapping>


--------------------------------------------------------------------------------------

Code:
package db;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Calendar;
import java.util.Set;
import java.util.Iterator;
import java.io.Serializable;

public class T_BASKET implements Serializable {

    // NAME TYPE (length) [ ( precision, scale ]
    // NETTINGNUMBER NUMBER (22)  (16,0)
    // INTERNALID NUMBER (22)  (8,0)
    // TRADEDATE DATE (7)
    // WKN CHAR (6)
    // ISIN VARCHAR2 (12)
    // RIC VARCHAR2 (50)

    protected BigDecimal nettingnumber;
    protected BigDecimal internalid;
    protected Calendar tradedate;
    protected String wkn;
    protected String isin;
    protected String ric;

    public T_BASKET() { }

    public BigDecimal getNettingnumber() { return nettingnumber; }
    public void setNettingnumber( BigDecimal nettingnumber ) { this.nettingnumber = nettingnumber; }

    public BigDecimal getInternalid() { return internalid; }
    public void setInternalid( BigDecimal internalid ) { this.internalid = internalid; }

    public Calendar getTradedate() { return tradedate; }
    public void setTradedate( Calendar tradedate ) { this.tradedate = tradedate; }

    public String getWkn() { return wkn; }
    public void setWkn( String wkn ) { this.wkn = wkn; }

    public String getIsin() { return isin; }
    public void setIsin( String isin ) { this.isin = isin; }

    public String getRic() { return ric; }
    public void setRic( String ric ) { this.ric = ric; }


    public String toString() {

        Object []columns = { nettingnumber, internalid, tradedate, wkn, isin, ric };
        String []names = { "nettingnumber", "internalid", "tradedate", "wkn", "isin", "ric" };

        StringBuffer sb1 = new StringBuffer();
        sb1.append( " T_BASKET : " );
        for ( int i = 0; i < columns.length; i++ ) {
            if ( i > 0 ) sb1.append( ", " );
            sb1.append( names[i] );
            sb1.append( " [" );
            sb1.append( columns[i] );
            sb1.append( "]" );
        }

        sb1.append(
          utils.ToStringUtils.setToString( "basketNettings", basketNettings ) );

        return sb1.toString();
    }

    public boolean equals( Object o ) {
        if ( this == o ) return true;
        if ( o == null ) return false;
        if ( !(o instanceof db.T_BASKET) ) return false;
        final db.T_BASKET _obj = (db.T_BASKET)o;
        if ( !this.internalid.equals( _obj.internalid ) ) return false;
        return true;
    }

    public int hashCode() {
        return (internalid == null) ? System.identityHashCode(this) : internalid.hashCode();
    }

    protected Set basketNettings;

    public Set getBasketNettings() { return basketNettings; }
    public void setBasketNettings( Set basketNettings ) { this.basketNettings = basketNettings; }

}

--------------------------------------------------------------------------------------

Code:
package db;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Calendar;
import java.util.Set;
import java.util.Iterator;
import java.io.Serializable;

public class T_NETTINGS implements Serializable {

    // NAME TYPE (length) [ ( precision, scale ]
    // NETTINGNUMBER NUMBER (22)  (16,0)
    // REFERENCENBR VARCHAR2 (16)
    // BOOK CHAR (3)
    // BUYSELL CHAR (1)
    // NOMINAL NUMBER (22)  (16,4)
    // PRICE NUMBER (22)  (17,8)
    // PRICECCY CHAR (3)

    protected BigDecimal nettingnumber;
    protected String referencenbr;
    protected String book;
    protected String buysell;
    protected BigDecimal nominal;
    protected BigDecimal price;
    protected String priceccy;

    public T_NETTINGS() { }

    public BigDecimal getNettingnumber() { return nettingnumber; }
    public void setNettingnumber( BigDecimal nettingnumber ) { this.nettingnumber = nettingnumber; }

    public String getReferencenbr() { return referencenbr; }
    public void setReferencenbr( String referencenbr ) { this.referencenbr = referencenbr; }

    public String getBook() { return book; }
    public void setBook( String book ) { this.book = book; }

    public String getBuysell() { return buysell; }
    public void setBuysell( String buysell ) { this.buysell = buysell; }

    public BigDecimal getNominal() { return nominal; }
    public void setNominal( BigDecimal nominal ) { this.nominal = nominal; }

    public BigDecimal getPrice() { return price; }
    public void setPrice( BigDecimal price ) { this.price = price; }

    public String getPriceccy() { return priceccy; }
    public void setPriceccy( String priceccy ) { this.priceccy = priceccy; }


    public String toString() {

        Object []columns = { nettingnumber, referencenbr, book, buysell, nominal, price, priceccy };
        String []names = { "nettingnumber", "referencenbr", "book", "buysell", "nominal", "price", "priceccy" };

        StringBuffer sb1 = new StringBuffer();
        sb1.append( " T_NETTINGS : " );
        for ( int i = 0; i < columns.length; i++ ) {
            if ( i > 0 ) sb1.append( ", " );
            sb1.append( names[i] );
            sb1.append( " [" );
            sb1.append( columns[i] );
            sb1.append( "]" );
        }


        return sb1.toString();
    }

    public boolean equals( Object o ) {
        if ( this == o ) return true;
        if ( o == null ) return false;
        if ( !(o instanceof db.T_NETTINGS) ) return false;
        final db.T_NETTINGS _obj = (db.T_NETTINGS)o;
        if ( !this.referencenbr.equals( _obj.referencenbr ) ) return false;
        return true;
    }

    public int hashCode() {
        return (referencenbr == null) ? System.identityHashCode(this) : referencenbr.hashCode();
    }


}


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.