我怀疑在jsf中建立这种关系,当我只有一对一这样的雇主和雇员时,我使用双向关系收集级联和懒惰,当我想编辑雇主时,雇主数据库我点击并转到页面编辑,它带有雇主和他们的雇员,可以修改雇主的数据,添加或删除员工,我有一个按钮,使保存节省雇主和员工级联。
@ Entity
{
public class Employer
@ Id
private int id;
@ OneToMany ( mappedBy = " employer " , cascade = Cascade.TYPE.ALL )
private List <Employee> employees ;
...
}
@ Entity
public class Employee {
@ ManyToOne
Employer private employer ;
...
}
@ ManagedBean
private Class MyMB {
private List <Employer> Employers ;
Employe private employer ;
private Employee employee ;
public void remove () {
employe.getEmployees.remove ( employee ) ;
}
public void add ( ) {
employer.getEmployees.add ( employee ) ;
}
public void save ( ) {
someService.persist ( employe ) ;
employes service.findAll = ();
}
}
acedito远没有问题,我最大的问题是当一个实体只有一个细节时 15个细节,例如我使用单向关系?应该单独购买我的收藏品吗? 我保存详细信息separamente master?正在考虑使用标签,每个标签到一个细节 例如,为雇员保存和保存雇主
@ ManagedBean
private Class MyMB {
private List <Employer> Employers ;
Employe private employer ;
private Employee employee ;
private List <Employees> employees ;
public void selectEmployer ( ) {
employer row.getData( ) ;
employees = employeeService.findEmployess ( employer ) ;
}
public void remove () {
employeeService.remove ( employee ) ;
employees = employeeService.findEmployess( employer ) ;
}
public void add ( ) {
employeeService.add ( employee ) ;
employees = employeeService.findEmployess ( employer ) ;
}
public void save ( ) {
someService.persist ( employe ) ;
employes = service.findAll();
}
}
这种方法是对的吗?还有其他更好的解决方案吗?我接受建议。