Reading the hibernate and xdoclet forums I can't seem to piece together a way of using hibernate composite keys using xdoclet.
For example, if I have a table that holds all the projects that an employee belongs to, with primary key columns empId, projId, with other non-key columns, projName, projLocation etc (I know this is not great but its just for the purposes of an example). I know that you'd have to build 2 classes, one for the composite primary key with getters setters for each column, a hashcode and toString, I dont know if you put xdoclet in this class. Then there is the "main" class that must "somehow" link to the composite class and have the usual property xdoclet for the non-key columns.
Heres a start if someone could fill in the blanks, I would be very grateful:
The composite key class:
package com.xxx;
/**
* @hibernate ???
*/
public class EmpProjPK implements java.io.Serializable
{
private int projId;
private int empId;
public EmpProjPK() {
}
/**
* @return int
* @hibernate ???
*/
public int getProjId() {
return projId;
}
public void setProjId(int projId) {
this.projId = projId;
}
/**
* @return int
* @hibernate ???
*/
public int getEmpId() {
return empId;
}
public void setEmpId(int empId) {
this.empId = empId;
}
public boolean equals(Object o) {
// Check equals ...
return true;
}
public int hashCode() {
int result = 17;
// Calc hash ...
return result;
}
}
The main class:
package com.xxx;
import java.util.*;
/**
*
* @hibernate.class
* table="emp_proj"
*/
public class EmpProj
implements java.io.Serializable
{
private String projName;
private EmpProjPK pk;
public EmpProj() {
pk = new EmpProjPK();
}
private int companyId;
public Compkeytest( int empId, int projId) {
pk.setEmpId(empId);
pk.setProjId(projId);
}
/**
*
* @hibernate.id
* generator-class="assigned" ???
*
* @return Compkeytest
*/
public EmpProjPK getEmpProjPK() {
return pk;
}
public void setEmpProjPK(EmpProjPK pk) {
this.pk = pk;
}
/**
* @return String
*
* @hibernate.property
* column="empName"
* not-null="false"
*/
public String getProjName() {
return this.projName;
}
/**
* @param description The empName to set
*/
public void setProjName(String projName) {
this.projName = projName;
}
}
|