I have an Evaluation
entity that has an associated list of EvaluationEvaluator
. I need to explicitly create that entity because it required an extra column "STATUS". Before I continue evaluation. I do: evaluation.setEvaluationEvaluator(listEvaluator)
where listEvaluator
is a list of EvaluationEvaluator
type. Then persist(evaluation)
. When I run this, it does not throw any kind of exception. But in the database, it inserts in the Evaluation
table, and not inserted into the EvaluationEvaluator
table.
Below my Evaluation entity.
@Entity
public class Evaluation implements Serializable{
@Id
@GeneratedValue
private Long id;
//MORE FIELDS
@OneToMany(mappedBy="evaluation")
private List<EvaluationEvaluator> evaluators;
//CONSTRUCTORS
//GETTER AND SETTERS
}
This is my EvalutionEvaluator Entity:
@Entity
@Table(name= "EVALUATION_EVALUATOR")
@IdClass(EvaluationEvaluatorId.class)
public class EvaluationEvaluator implements Serializable{
@Id
@Column(name="EMPLOYEE_ID", insertable=false , updatable=false)
private Long EmployeeID;
@Id
@Column(name="EVALUATION_ID", insertable=false, updatable=false)
private Long EvaluationID;
@ManyToOne
@JoinColumn(name"EMPLOYEE_ID")
private Employee employee;
@ManyToOne
@JoinColumn(name"EVALUATION_ID")
private Evaluation evaluation;
@NotNull
private String status;
//CONSTRUCTORS
//GETTER AND SETTERS
}
This is my EvaluationEvaluatorId class
public class EvaluationEvaluatorId implements Serializable{
private Long employeeID;
private Long evaluationID;
//CONSTRUCTOR
//GETTER AND SETTERS
}
And finally, this is my EvaluationBean class
@Stateful
@Named
@LocalBean
@ConversationScoped
public class EvaluationBean {
@PersistentContext(type= PersistenceContextType.EXTENDED)
private EntityManager em;
@Inject
Conversation conversation;
private Evaluation evaluation;
//IN MY WEBPAGE I IMPLEMENT PRIMEFACES PICKLIST AND IT REQUIRE DUALIST TO HANDLE
private DualListModel<Employe> evaluators;
private EvaluationEvaluator evaluationEvaluator;
private List<EvaluationEvaluator> listEvaluators;
@Inject
private EmployeeList employeeList;
//GETTER AND SETTERS
public String begin(){
if (conversation.isTransient()){
converstaion.begin();
}
evaluationEvaluator = new EvaluationEvaluator();
listEvaluators = new ArrayList<EvaluationEvaluator>();
evaluation = new Evaluation();
List<Employee> source = employeeList.findAll();
target = new ArrayList<Employee>();
evaluators = new DualListModel<Employee>(source, target);
return "/evalution/evaluationAsig.xhtml"
}
public String save(){
Iterator<Employee> iterator = evaluators.getTarget().iterator();
while (iterator.hasNext()){
EvaluationEvaluator ev = new EvaluationEvaluator();
ev.setEmployee(iterator.next());
listEvaluators.add(ev);
}
evalution.setEvaluationEvaluators(listEvaluators);
if(evaluation.getId()==null){
em.persist(evalution);
} else{
em.merge(evalution);
}
if(!conversation.isTransient()){
convesation.end();
}
return "/evalution/evaluationsAsig.xhtml"
}
}
When I debug my application,apparently everything is correct, but I mentioned above, doesn't persist in EvaluationEvaluator
table.