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;
}
}
|