Hi All,
Unable to generate .hbm file..
Using Oracle 8i & hibernate 2.1
I have 2 tables
a) Department Table
b) Divsion Table
The Department Table contains 2 primary keys deptid and divid..
these are associated to the Division tabel as foreign keys..
TblMst_Department.java:
Code:
public class TblMst_Department {
private int dpt_DeptCode;
private int dpt_DivCode;
private String dpt_DeptName;
private String dpt_Dept_Short_Name;
private String dpt_Dept_Manager_Name;
private String dpt_Dept_BL_Name;
private String dpt_Dept_BL_Short_Name;
private String dpt_Dept_BL_Manager_Name;
private String dpt_Dept_Frz_Flag;
private String dpt_Dept_RegionCode;
private String dpt_CreateBy;
private Date dpt_CreateDate;
private String dpt_ModifiedBy;
private Date dpt_ModifiedDate;
private TblMst_Division tbldiv;
// generate getters and setters
}
Code:
public class TblMst_Division {
private int dpt_DeptCode;
private int dpt_DivCode;
private String dvn_Div_Name;
private String dvn_Div_Short_Name;
private String dvn_Div_Comp_Code;
private String dvn_Div_Addr1;
private String dvn_Div_Addr2;
private String dvn_Div_Manager_Name;
private String dvn_Div_Phone;
private String dvn_Div_Fax;
private String dvn_Div_BL_Name;
private String dvn_Div_BL_Short_Name;
private String dvn_Div_BL_Addr1;
private String dvn_Div_BL_Addr2;
private String dvn_Div_BL_Addr3;
private String dvn_Div_BL_Manager_Name;
private String dvn_Div_Frz_Flag;
private String dvn_Div_Contra_Acct_Code;
private String dvn_DeleteFlag;
private String dvn_CreateBy;
private Date dvn_CreateDate;
private Date dvn_ModifiedDate;
private String dvn_Div_Addr3;
private String dvn_ModifiedBy;
// generate getters and setters
}
My problem is to insert the values from the implementation file..
InsertService .java
Code:
public class InsertService {
public InsertService() {
super();
}
private static SessionFactory sessionFactory;
static {
Configuration cfg = new Configuration();
try {
cfg.addFile(
"TblMst_Department.hbm.xml");
cfg.addFile("TblMst_Division.hbm.xml");
sessionFactory = cfg.buildSessionFactory();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void add() {
Session session = null;
Transaction tx = null;
try {
session = sessionFactory.openSession();
tx = session.beginTransaction();
TblMst_Division div = new TblMst_Division();
div.setDpt_DeptCode(1);
div.setDpt_DivCode(2);
div.setDvn_CreateBy("reddy");
div.setDvn_CreateDate(new Date());
div.setDvn_DeleteFlag("Y");
div.setDvn_Div_Addr1("");
div.setDvn_Div_Addr2("");
div.setDvn_Div_Addr3("");
div.setDvn_Div_BL_Addr1("");
div.setDvn_Div_BL_Addr2("");
div.setDvn_Div_BL_Addr3("");
div.setDvn_Div_BL_Manager_Name("");
div.setDvn_Div_BL_Name("");
div.setDvn_Div_BL_Short_Name("");
div.setDvn_Div_Comp_Code("");
div.setDvn_Div_Contra_Acct_Code("");
div.setDvn_Div_Fax("");
div.setDvn_Div_Frz_Flag("");
div.setDvn_Div_Manager_Name("");
div.setDvn_Div_Name("");
div.setDvn_Div_Phone("");
div.setDvn_Div_Short_Name("");
div.setDvn_ModifiedBy("");
div.setDvn_ModifiedDate(new Date());
TblMst_Department dept = new TblMst_Department();
dept.setTbldiv(div);
dept.setDpt_DeptCode(1);
dept.setDpt_DivCode(2);
dept.setDpt_DeptName("");
dept.setDpt_Dept_Short_Name("");
dept.setDpt_Dept_Manager_Name("");
dept.setDpt_Dept_BL_Name("");
dept.setDpt_Dept_BL_Short_Name("");
dept.setDpt_Dept_BL_Manager_Name("");
dept.setDpt_Dept_Frz_Flag("");
dept.setDpt_Dept_RegionCode("");
dept.setDpt_Dept_RegionCode("");
dept.setDpt_CreateBy("");
dept.setDpt_CreateDate(new Date());
dept.setDpt_ModifiedBy("");
dept.setDpt_ModifiedDate(new Date());
session.save(div);
session.save(dept);
session.flush();
session.connection().commit();
session.close();
tx.commit();
System.out.println("Success");
} catch (Exception ex) {
try {
if (tx != null)
tx.rollback();
} catch (Exception iex) {
}
System.err.println(ex);
} finally {
try {
if (session != null)
session.close();
} catch (Exception ex) {
}
}
}
public static void main(String arg[]) {
InsertService iService = new InsertService();
iService.add();
}
}
Can u please help me out in writing .hbm file and getting the values inserted in the d/b
Thanks a lot..
regards
Krishna Reddy