First of all, happy new year to everyone.
Dear all,
I am using Hibernate 3.0
I am getting the class cast exception. Please help me to solve this issue. I checked for the datatype of the attributes in the POJO, hbm.xml and also in the Database. I believe there is no problem with that.
There is a Tabe called RELATN, which have a composite key consist of 5 attributes.
RELATN.java
Code:
package nulamda.Bean;
import java.math.BigDecimal;
import java.sql.Timestamp;
public class RELATN {
//All Getter and setter except for the composite primary keys
//its all in the RELATN_PK class
private BigDecimal AssigneeInterestPct;
private byte BenefitIndicator;
private BigDecimal BENFCPC;
private byte CreatorTypeCode;
private BigDecimal NomineeInterestPct;
private short PseudoBeneficiaryId;
private byte RelatnStat;
private byte RoleIndicator;
private Timestamp CreatedDate;
private String CreatorId;
//Variable for composite key class
private RELATN_PK relatn_pk;
private CLIENT client;
public RELATN() {
// TODO Auto-generated constructor stub
}
public BigDecimal getAssigneeInterestPct() {
return AssigneeInterestPct;
}
public void setAssigneeInterestPct(BigDecimal assigneeInterestPct) {
AssigneeInterestPct = assigneeInterestPct;
}
public byte getBenefitIndicator() {
return BenefitIndicator;
}
public void setBenefitIndicator(byte benefitIndicator) {
BenefitIndicator = benefitIndicator;
}
public BigDecimal getBENFCPC() {
return BENFCPC;
}
public void setBENFCPC(BigDecimal benfcpc) {
BENFCPC = benfcpc;
}
public byte getCreatorTypeCode() {
return CreatorTypeCode;
}
public void setCreatorTypeCode(byte creatorTypeCode) {
CreatorTypeCode = creatorTypeCode;
}
public BigDecimal getNomineeInterestPct() {
return NomineeInterestPct;
}
public void setNomineeInterestPct(BigDecimal nomineeInterestPct) {
NomineeInterestPct = nomineeInterestPct;
}
public short getPseudoBeneficiaryId() {
return PseudoBeneficiaryId;
}
public void setPseudoBeneficiaryId(short pseudoBeneficiaryId) {
PseudoBeneficiaryId = pseudoBeneficiaryId;
}
public byte getRelatnStat() {
return RelatnStat;
}
public void setRelatnStat(byte relatnStat) {
RelatnStat = relatnStat;
}
public byte getRoleIndicator() {
return RoleIndicator;
}
public void setRoleIndicator(byte roleIndicator) {
RoleIndicator = roleIndicator;
}
public Timestamp getCreatedDate() {
return CreatedDate;
}
public void setCreatedDate(Timestamp createdDate) {
CreatedDate = createdDate;
}
public String getCreatorId() {
return CreatorId;
}
public void setCreatorId(String creatorId) {
CreatorId = creatorId;
}
public RELATN_PK getRelatn_pk() {
return relatn_pk;
}
public void setRelatn_pk(RELATN_PK relatn_pk) {
this.relatn_pk = relatn_pk;
}
public CLIENT getClient() {
return client;
}
public void setClient(CLIENT client) {
this.client = client;
}
}
RELATN_PK.javaCode:
package nulamda.Bean;
import java.io.Serializable;
public class RELATN_PK implements Serializable {
private static final long serialVersionUID = 1L;
private int CLNO;
private int DEEDTYPE;
private String PLANNO;
private byte RELATION;
private int RelationSeqNo;
public RELATN_PK() {
// TODO Auto-generated constructor stub
}
public int getCLNO() {
return CLNO;
}
public void setCLNO(int clno) {
CLNO = clno;
}
public int getDEEDTYPE() {
return DEEDTYPE;
}
public void setDEEDTYPE(int deedtype) {
DEEDTYPE = deedtype;
}
public String getPLANNO() {
return PLANNO;
}
public void setPLANNO(String planno) {
PLANNO = planno;
}
public int getRELATION() {
return RELATION;
}
public void setRELATION(byte relation) {
RELATION = relation;
}
public int getRelationSeqNo() {
return RelationSeqNo;
}
public void setRelationSeqNo(int relationSeqNo) {
RelationSeqNo = relationSeqNo;
}
/*
* The identifier class must override equals() and hashCode() and implement.
Serializable. The disadvantage of this approach is quite obviouscode
duplication.
* */
@Override
public boolean equals(Object other) {
try {
if (this == other)return true;
if ( !(other instanceof RELATN_PK))return false;
final RELATN_PK relatn_PK = (RELATN_PK) other;
if (!( relatn_PK.getCLNO() == getCLNO()) ) return false;
if (!( relatn_PK.getDEEDTYPE() == getDEEDTYPE()) ) return false;
if (!( relatn_PK.getPLANNO() == getPLANNO()) ) return false;
if (!( relatn_PK.getRELATION() == getRELATION()) ) return false;
if (!( relatn_PK.getRelationSeqNo() == getRelationSeqNo()) ) return false;
return true;
} catch (Exception e) {
System.out.println("inside the boolean class exception");
return false;
}
}
@Override
public int hashCode() {
int result = 0;
try {
result = getPLANNO().hashCode();
result = (int) 29 * result;
return result;
} catch (Exception e) {
System.out.println("inside the hashcode method exception");
return result;
}
}
}
RELATN.hbm.xmlCode:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="nulamda.Bean.RELATN" table="RELATN" lazy="false" >
<composite-id class="nulamda.Bean.RELATN_PK"
name="relatn_pk" access="property">
<key-property name="CLNO" type="integer"></key-property>
<key-property name="DEEDTYPE" type="integer"></key-property>
<key-property name="PLANNO" type="string" ></key-property>
<key-property name="RELATION" type="byte"></key-property>
<key-property name="RelationSeqNo" type="integer"></key-property>
</composite-id>
<property name="AssigneeInterestPct" type="big_decimal"></property>
<property name="BenefitIndicator" type="byte"></property>
<property name="BENFCPC" type="big_decimal"></property>
<property name="CreatorTypeCode" type="byte"></property>
<property name="NomineeInterestPct" type="big_decimal"></property>
<property name="PseudoBeneficiaryId" type="short"></property>
<property name="RelatnStat" type="byte"></property>
<property name="RoleIndicator" type="byte"></property>
</class>
</hibernate-mapping>
The class getting the detailsCode:
package nulamda.Support;
import java.util.List;
import nulamda.Bean.RELATN;
import nulamda.Bean.RELATN_PK;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;
public class RelatnSupport {
public void GetRelatnDetails()
{
Session session = HibernateSessionFactory.currentSession();
Transaction transaction = session.beginTransaction();
Criteria relatnCriteria = session.createCriteria(RELATN.class);
RELATN_PK relatn_pk = new RELATN_PK();
relatn_pk.setPLANNO("111111111x1");
relatnCriteria.add(Restrictions.eq("relatn_pk", relatn_pk));
List<RELATN> relatnList = relatnCriteria.list();
System.out.println("size of the returned relatn list is : "+ relatnList.size());
transaction.commit();
}
}
Error messageCode:
package nulamda.Support;
import java.util.List;
import nulamda.Bean.RELATN;
import nulamda.Bean.RELATN_PK;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;
public class RelatnSupport {
public void GetRelatnDetails()
{
Session session = HibernateSessionFactory.currentSession();
Transaction transaction = session.beginTransaction();
Criteria relatnCriteria = session.createCriteria(RELATN.class);
RELATN_PK relatn_pk = new RELATN_PK();
relatn_pk.setPLANNO("111111111x1");
relatnCriteria.add(Restrictions.eq("relatn_pk", relatn_pk));
List<RELATN> relatnList = relatnCriteria.list();
System.out.println("size of the returned relatn list is : "+ relatnList.size());
transaction.commit();
}
}
Please help me to solve the issue. Thanks in advance[/b]