title: How to map foreign key relations in hibernate
body: <p>I have customer class   and Address class  as below:
  officeAddressId,homeAddressId, and secondaryAddressId in Customer class are for foreign key mapping in tables.</p>
  
  <pre><code>  public class customer implements serializable
      {
      private static final long serialVersionUID= -5830229553758180137L;
      int age;
      String officeAddressId= null;
      String homeAddressId= null;
      String secondaryAddressId= null;
      }
  
  public class Address implements serializable
  {
          private static final long serialVersionUID= -5130229553758180137L;
          private String              addressId           = null;
      private String              addressLine         = null;
      private String              cityName            = null;
      private String              stateName           = null;
      private String              countryName         = null;
      private String              pincode             = null;
  }
  </code></pre>
  
  <p>My database table is straight forward:</p>
  
  <pre><code>CREATE TABLE customer
  (
  customerID varchar(40) primary key,
  officeAddressId varchar(40),
  homeAddressId varchar(40),
  secondaryAddressId varchar(40),
  age int 
  );
  
  CREATE TABLE Address
  (
  addressID varchar(40) primary key,
  addressLine varchar(40),
  cityName varchar(40),
  stateName varchar(40),
  countryName varchar(40),
  pincode varchar(10),
  );
  </code></pre>
  
  <p>I make address objects (3 objects for address one for home,office and secondarycontact)  and customer object at service layer and open transaction. I am not sure how should I give the foreign key relation in hbm mapping files and how do I save these four objects(3 address objects and 1 customer object) and in which order that the foreign key relations are persisted in database correctly.</p>
  
  <p>Thanks in advance....</p>