Hi all,
This is my first post in the hibernate forum. Hope ill get the answer for my question.
Hibernate version --- 3.3.1
Database --- Ms SQL server 2005
I am having a legacy table called "
RELATN" with a composite key consists of five columns. 1,2,3,4 and 5 in the following list.
1
CLNO (P) --- int
2
PLANNO (P) --- char
3
RELATION (P) --- tinyint
4
DEEDTYPE (P) --- int
5
RelationSeqNo (P) --- int
5 BENFCPC --- money
7 LASTUPD --- varchar
8 CreatorId --- char
9 CreatorTypeCode --- tinyint
10 CreatedDate datetime
11 PseudoBeneficiaryId --- smallint
12 AssigneeInterestPct --- money
13 NomineeInterestPct --- money
14 RelatnStat tinyint
15 RoleIndicator --- tinyint
16 BenefitIndicator --- tinyint
I used <composite-ID>. Here is my
RELATN.hbm.xml
Code:
<?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="com.tcs.Nulamda.hibernate.RELATN.java" table="RELATN">
<composite-id class="com.tcs.Nulamda.hibernate.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="byte"></property>
<property name="RelatnStat" type="byte"></property>
<property name="RoleIndicator" type="byte"></property>
</class>
</hibernate-mapping>
And here is the java class ...RELATN.java
Code:
package com.tcs.Nulamda.hibernate;
import java.math.BigDecimal;
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 byte PseudoBeneficiaryId;
private byte RelatnStat;
private byte RoleIndicator;
//Variable for composite key class
private RELATN_PK relatn_pk;
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 byte getPseudoBeneficiaryId() {
return PseudoBeneficiaryId;
}
public void setPseudoBeneficiaryId(byte 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 RELATN_PK getRelatn_pk() {
return relatn_pk;
}
public void setRelatn_pk(RELATN_PK relatn_pk) {
this.relatn_pk = relatn_pk;
}
}
And here is the [b]RELATN_PKCode:
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) {
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;
}
@Override
public int hashCode() {
int result;
result = getPLANNO().hashCode();
result = 29 * result;
return result;
}
}
If i remove the RELATN.hbm.xml path in the hibernate.cfg.xml file. Everythings works fine. So can you please tell me what is the problem.