0

我对在 jsf 中建立这种关系有疑问,当我只有一个这样的雇主和雇员时,我使用具有级联和惰性的双向关系 Collection ,当我想编辑雇主时,我点击雇主数据表并转到页面编辑,它带有雇主及其雇员,可以修改雇主的数据并添加或删除雇员,其中我有一个按钮,可以保存级联保存雇主和雇员。

@ 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();
}
}

这种做法正确吗?还有其他更好的解决方案吗?我接受建议。

4

0 回答 0