-->
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.  [ 1 post ] 
Author Message
 Post subject: One to One mapping with a Composite Key
PostPosted: Thu Oct 19, 2006 8:40 am 
Newbie

Joined: Fri Mar 19, 2004 3:53 pm
Posts: 6
I have the following scenario:
I have a BAPDocument object that has a composite key that is made up of the following fields: fiscalYear and documentNumber.
The BAPDocument has an Employee object that also has a composite key that is made up of the following fields: fiscalYear and documentNumber.
The BAPDocument object is mapped to a table called bbab20h and the Employee object is mapped to a table called bbab20e. The composite key of the bbab20h (BAPDocument) table consists of bbab20h_cdfsyr (fiscalYear) and bbab20h_nodocu (documentNumber). The composite key of the bbab20e (Employee) table consists of bbab20e_cdfsyr (fiscalYear) and bbab20e_nodocu (documentNumber).
There is a one-to-one relationship between BAPDocument and Employee where the Employee can't exist without a BAPDocument being created first.
I want to know the best strategy to map the BAPDocument and the Employee object so that when I get the BAPDocument for a specific fiscalYear and documentNumber I also get the corresponding Employee object and it joins the two classes on the fiscalYear and documentNumber fields. This is a legacy database so I can't change the database structure.

Hibernate version: 3.1.3

XDoclet version: 1.3-SNAPSHOT

Name and version of the database you are using:Mysql 4.024


Code:
/**
* BAPDocument Object
* @author ctk552
* @hibernate.class table = "BBAB20H"
*/
public class BAPDocument {
   
   private BAPDocumentCompositeId id;   
   private Employee employee;

   /**
    * @return the id
    * @hibernate.id type="com.epp.model.BAPDocumentCompositeId"
    */
   public BAPDocumentCompositeId getId() {
      return id;
   }

   /**
    * @return the employee
    * @hibernate.one-to-one
    */
   public Employee getEmployee() {
      return employee;
   }

}



Code:
public class BAPDocumentCompositeId implements Serializable{

   private String fiscalYear;
   private String documentNumber;

   /**
    * @return the fiscalYear
    * @hibernate.property column = "BBAB20H_CDFSYR"
    */
   public String getFiscalYear() {
      return fiscalYear;
   }
   /**
    * @return the documentNumber
    * @hibernate.property column = "BBAB20H_NODOCU"
    */
   public String getDocumentNumber() {
      return documentNumber;
   }




Code:
/**
* Employee Object
* @author ctk552
* @hibernate.class table = "BBAB20E"
*/
public class Employee {
   private EmployeeCompositeId id;
   private String lastName;
   private String firstName;

   /**
    * @return the id
    * @hibernate.id type="com.epp.model.EmployeeCompositeId"
    */
   public EmployeeCompositeId getId() {
      return id;
   }   
}


Code:
public class EmployeeCompositeId implements Serializable{
   private String fiscalYear;
   private String documentNumber;
   /**
    * @return the fiscalYear
    * @hibernate.property column="BBAB20E_CDFSYR"
    */
   public String getFiscalYear() {
      return fiscalYear;
   }
   /**
    * @return the documentNumber
    * @hibernate.property column="BBAB20E_NODOCU"
    */
   public String getDocumentNumber() {
      return documentNumber;
   }
}



Thanks for your help!


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

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.