Hi all!
I'm trying to save a Subclass but I'm getting a ClassCastException.
these are my classes:
Code:
public class Tariff implements Serializable
{
private ClientType clientType;
private Calendar fromDate;
private String name;
private Double markUp;
//getters, setters, equals(), hashCode()...
}
public class CommissionableTariff extends Tariff
{
private Double commission;
//getters, setters
}
public class NetTariff extends Tariff
{
//getters, setters
}
this is my hiberntate mapping:
Code:
<class name="es.tariff.Tariff" discriminator-value="T">
<composite-id>
<key-many-to-one name="clientType" class="es.agency.ClientType" column="clientType"/>
<key-property name="fromDate" type="date"/>
</composite-id>
<discriminator column="type" type="character" />
<property name="name" type="string"/>
<property name="markUp" type="double" length="12"/>
<subclass name="es.tariff.NetTariff"
discriminator-value="N" dynamic-update="true"
dynamic-insert="true">
</subclass>
<subclass name="es.tariff.CommissionableTariff"
discriminator-value="C" dynamic-update="true"
dynamic-insert="true">
<property name="commission" type="double" length="12"/>
</subclass>
</class>
Is this mapping right?
So this is the java code where I try to save the new instance of a NetTariff:
Code:
ClientType clientType = (ClientType)HibernateSession.currentSession().load(ClientType.class, new Long(rq.getClientTypeCode()));
Calendar fromDate = rq.getTariffFromDate();
Double markUp = new Double(NumberUtils.getDouble(rq.getTariffMarkUpInt(),rq.getTariffMarkUpDec()));
String name = rq.getTariffName();
NetTariff nTariff = new NetTariff();
nTariff.setClientType(clientType);
nTariff.setFromDate(fromDate);
nTariff.setMarkUp(markUp);
nTariff.setName(name);
HibernateSession.currentSession().saveOrUpdate(nTariff);
HibernateSession.currentSession().flush();
And after saving I get a class cast exception...
Why is this?
can u give the stack trace of the Exception??
Thank you very much in advance!!!