Hi All
I have a table with 2 composite keys(which makes primary key).one is of string type(dty_Doc_Type) and the other int type(dty_Year)..
Basing on the above, when i am trying to insert fields hibernate is throwing
net.sf.hibernate.MappingException: No persister for: com.webify.ccpa.db.hibernate.CompositeKey
- I have a main class as TblMst_Document_Type
-I have also created a separate class CompositeKey for placing the 2 columns..
-Mapping file for TblMst_Document_Type :
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.webify.ccpa.db.hibernate.TblMst_Document_Type" table="tblmst_document_type">
<composite-id class="com.webify.ccpa.db.hibernate.CompositeKey" name="id">
<key-property name="dty_Doc_Type" column="dty_Doc_Type"/>
<key-property name="dty_Year" column="dty_Year"/>
</composite-id>
<property name="dty_CreateBy"/>
<property name="dty_CreateDate"/>
<property name="dty_Doc_desc"/>
<property name="dty_Initial_Doc_Number"/>
<property name="dty_Last_Doc_Number"/>
<property name="dty_ModifiedBy"/>
<property name="dty_ModifiedDate"/>
<property name="dty_deleteflag"/>
</class>
</hibernate-mapping>
<!-- parsed in 30ms -->
Service class will have a function like:
Code:
public void insertParameterValues(TblMst_Document_Type doc) {
Transaction tx = null;
CompositeKey ck = new CompositeKey();
try {
session = sessionFactory.openSession();
tx = session.beginTransaction();
if(doc == null)
doc = new TblMst_Document_Type();
ck.setDty_Doc_Type("D0001");
ck.setDty_Year(2003);
doc.setdty_Doc_desc("XYZ");
doc.setdty_ModifiedBy("KReddy");
session.save(ck);
session.save(doc);
session.flush();
session.connection().commit();
tx.commit();
System.out.println("Inserted");
} catch (HibernateException hibex) {
try {
if (tx != null)
tx.rollback();
} catch (Exception iex) {
}
System.err.println(hibex);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
if (session != null)
session.close();
} catch (Exception ex) {
}
}
}
Can u pl guide me where i am wrong?
TblMst_Document_Type Code:
Code:
private String dty_Doc_Type;
private int dty_Year;
private String dty_Doc_desc;
private String dty_Last_Doc_Number;
private String dty_Initial_Doc_Number;
private String dty_deleteflag;
private String dty_CreateBy;
private Date dty_CreateDate;
private String dty_ModifiedBy;
private Date dty_ModifiedDate;
private CompositeKey id;
// generate getter and setter
// aslo overriden hascode and equals method
ComposteKey Code:
Code:
public class CompositeKey implements Serializable {
private String dty_Doc_Type;
private int dty_Year;
/**
* getDty_Doc_Type
* String
*/
public String getDty_Doc_Type() {
return dty_Doc_Type;
}
/**
* getDty_Year
* int
*/
public int getDty_Year() {
return dty_Year;
}
/**
* setDty_Doc_Type
* void
*/
public void setDty_Doc_Type(String string) {
dty_Doc_Type = string;
}
/**
* setDty_Year
* void
*/
public void setDty_Year(int i) {
dty_Year = i;
}
public boolean equals(Object obj) {
if (obj instanceof TblMst_Document_Type) {
if (dty_Doc_Type == ((TblMst_Document_Type) obj).getdty_Doc_Type()
&& dty_Year == ((TblMst_Document_Type) obj).getdty_Year())
return true;
}
return false;
}
/**
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return new Integer(dty_Year).hashCode()+dty_Doc_Type.hashCode();
}
}
Please guide me where i am going wrong??
Thanks and Regards
Krishna