-->
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: java.lang.ClassCastException on doing transaction.commit()
PostPosted: Fri May 14, 2004 3:22 pm 
Beginner
Beginner

Joined: Thu Feb 26, 2004 11:32 am
Posts: 32
Hi:
I am implementing a Table-per-class-hierarchy stratagey. I have 3 classes CCSTransaction, ContributionTransaction and InterestTransaction.On trying to do a transaction.commit() after a write I get the following exceptions :

java.lang.ClassCastException
at net.sf.hibernate.type.IntegerType.set(IntegerType.java:31)
at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:48)
at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:35)
at net.sf.hibernate.persister.EntityPersister.dehydrate(EntityPersister.java:393)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:466)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:442)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2382)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2335)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at Test.main(Test.java:54)


Any pointers on what I am missing over here would be great.

TIA

splash


My driver code :

class Test{

public static void main(String args[])
{
SessionFactory sf =null;
Session session = null;
CCSTransaction nextemp = null ;
Transaction tx = null;
try{

sf = new Configuration()
.addClass(CCSTransaction.class)
.buildSessionFactory();


session = sf.openSession();


InterestTransaction iTrans = new InterestTransaction(5,500.50, new Date() ) ;
tx = session.beginTransaction();
session.save(iTrans);
tx.commit();
session.close();

}catch (Exception e) {

System.out.println("Exception " + e) ;
e.printStackTrace();
}

}

}

My mapping file :

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

<hibernate-mapping>


<class name="CCSTransaction" table="TRANSACTION">
<id name="transactionId" type="int" column="TRANSACTION_ID">
<generator class="native"/>
</id>
<discriminator column="TRANSACTION_TYPE" type="string"/>
<property name="amount" column="AMOUNT" type="int"/>
<property name="effectiveDate" column="EFFECTIVE_DATE" type="java.util.Date"/>


<subclass name="InterestTransaction" discriminator-value="INTEREST">

</subclass>
<subclass name="ContributionTransaction" discriminator-value="CONTRIBUTION">
</subclass>

</class>

</hibernate-mapping>





My classes are as follows:


public class CCSTransaction{
int transactionId=0;
Date effectiveDate=null;
double amount=0;


public int getTransactionId()
{
return transactionId;
}

public void setTransactionId(int transactionId)
{
this.transactionId = transactionId;
}

public Date getEffectiveDate()
{
return effectiveDate;
}
public void setEffectiveDate(Date effectiveDate)
{
this.effectiveDate = effectiveDate;
}
public double getAmount()
{
return amount;
}
public void setAmount(double amount)
{
this.amount = amount;
}

public boolean equals(Object other) {
if ( !(other instanceof CCSTransaction) ) return false;
CCSTransaction castOther = (CCSTransaction) other;
return new EqualsBuilder()
.append(this.getTransactionId(), castOther.getTransactionId())
.isEquals();
}

public int hashCode() {
return new HashCodeBuilder()
.append(getTransactionId())
.toHashCode();
}
}


public class ContributionTransaction extends CCSTransaction {

}


public class InterestTransaction extends CCSTransaction {

public InterestTransaction(){}

public InterestTransaction( int transactionId,
double amount,
Date effectiveDate
)
{
this.transactionId=transactionId;
this.amount=amount;
this.effectiveDate = effectiveDate;

}



}


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 14, 2004 4:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
ammount is a double property, use type="double"


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.