POJO定义中的N + 1关系

时间:2012-11-03 06:19:45

标签: java

我对1 + N关系船有疑问。我设计了如下POJO,其中包含Workplace和Employee的关系。

1 + N - >一家公司很多员工

public class WorkplaceDetail implements Serializable {

private static final long serialVersionUID = -6760386803958725272L;
private int code;
private String plant;
private String compRegNum;
private String numOfEmps;
private List <Employee> employee = new ArrayList<Employee>();
      private Address address;
}

public class Employee{

private String empName;
private int empNumber;
      private Address address;
}

公共类地址{

private String primaryPhone;
private String secPhone;
private String mobileNum;
private String fax;
private String zip;
private String add1;
private String add2;

}

员工属于一个工作场所的N + 1关系。

public class WorkplaceDetail implements Serializable {

private static final long serialVersionUID = -6760386803958725272L;
private int code;
private String plant;
private String compRegNum;
private String numOfEmps;   
}

public class Employee{


private String empName;
private int empNumber;
    private WorkplaceDetail WorkplaceDetail;
}

请告诉我哪一种方法正确。

1 个答案:

答案 0 :(得分:0)

这是你的答案。请注意,这只是一个与您应该处理的配置相关的代码段。

public class Address {

private String primaryPhone;
private String secPhone;
private String mobileNum;
private String fax;
private String zip;
private String add1;
private String add2;
//As you said one to one relationship
private Employee employee;
private WorkplaceDetail workplaceDetail;
}

public class Employee{

private String empName;
private int empNumber;
private Address address;
private WorkplaceDetail workplaceDetail;
}

public class WorkplaceDetail implements Serializable {

private static final long serialVersionUID = -6760386803958725272L;
private int code;
private String plant;
private String compRegNum;
private String numOfEmps;
private List <Employee> employee = new ArrayList<Employee>();
private Address address;
}

希望这可以帮助你......!