-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: problem with keys
PostPosted: Mon Sep 29, 2003 11:04 am 
Newbie

Joined: Fri Sep 26, 2003 10:46 am
Posts: 6
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 29, 2003 6:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Compound keys need the assigned property for the id generator. You can try out the Middlegen plugin to see what it generates as a valid hbm file against your schema. Even if you don't use it in the long term, it can be educational trying out the various options. Also, the examples section has a new download involving the toolset that may also be of interest to you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.