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!