-->
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.  [ 8 posts ] 
Author Message
 Post subject: one-to-one ClassCastException
PostPosted: Wed Jan 21, 2004 8:51 pm 
Regular
Regular

Joined: Tue Oct 14, 2003 11:11 pm
Posts: 62
Location: Brasil/Curitiba
Hi,

I have the following mappings:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
    <class name="org.scaf.model.FamiliaVO" table="familia">
       
        <id name="numeroInscricao" column="numero_inscricao" type="string">
            <generator class="assigned" />
        </id>

        <property name="endereco" column="endereco" type="string" />
       
    </class>
</hibernate-mapping>


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

<hibernate-mapping>

    <class name="org.scaf.model.DesligamentoVO" table="desligamento">

        <id name="numeroInscricao" column="numero_inscricao" type="string">
            <generator class="assigned" />
        </id>

        <property name="dataDesligamento" column="data_desligamento" type="date" />

        <one-to-one name="familia" class="org.scaf.model.FamiliaVO" constrained="true" />
    </class>
</hibernate-mapping>



the DesligamentoVO has a one-to-one association with FamiliaVO, with String primary key...

when I load the DesligamentoVO, I have a ClassCastException..

in the class net.sf.hibernate.type.StringType,
the method
Code:
public void set(PreparedStatement st, Object value, int index) throws SQLException {
      st.setString(index, (String) value);
   }


receives a Integer paramenter "value", but my primary key is a string then a ClassCast occurs


any idea?

thanks

_________________
Ricardo Lecheta


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 1:45 am 
Beginner
Beginner

Joined: Thu Jan 08, 2004 4:40 am
Posts: 48
Location: Bangkok, Thailand
In my situation of using one-to-one, I always put property-ref in mapping file as well like this:
<one-to-one
name="offAddressHibernate"
class="com.netplus.pprincess.hibernate.OfficeAddressHibernate"
cascade="all"
outer-join="auto"
constrained="false"
property-ref="memberIdOff"
/>
and I think this might useful for you.
Cheers

_________________
<name>arin</name>
<at>netplus software</at>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 6:33 am 
Regular
Regular

Joined: Tue Oct 14, 2003 11:11 pm
Posts: 62
Location: Brasil/Curitiba
I

_________________
Ricardo Lecheta


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 6:34 am 
Regular
Regular

Joined: Tue Oct 14, 2003 11:11 pm
Posts: 62
Location: Brasil/Curitiba
Code:
<one-to-one name="familia" class="org.scaf.model.FamiliaVO" constrained="false" property-ref="numeroInscricao" />

_________________
Ricardo Lecheta


Top
 Profile  
 
 Post subject: Re: one-to-one ClassCastException
PostPosted: Thu Jan 22, 2004 8:26 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Ricardo wrote:
any idea?

If your POJO should use String instead of int or Integer

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: one-to-one ClassCastException
PostPosted: Thu Jan 22, 2004 12:11 pm 
Regular
Regular

Joined: Tue Oct 14, 2003 11:11 pm
Posts: 62
Location: Brasil/Curitiba
emmanuel wrote:
Ricardo wrote:
any idea?

If your POJO should use String instead of int or Integer


in this case, the primary key must be a String....

I've tested the one-to-one with Integer pk and it works well...

is there a problem with the String primary key?

_________________
Ricardo Lecheta


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 1:26 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
show your POJO

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 4:53 pm 
Regular
Regular

Joined: Tue Oct 14, 2003 11:11 pm
Posts: 62
Location: Brasil/Curitiba
guys,

I did a stupid error.

I was loading the object with an Integer... sorry

_________________
Ricardo Lecheta


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.