Hello,
I am still new to EJB3.0 however I try to get it running. My Problem right now is, that I have two entities. One is Company, the other one Employee. The Employee is stored in a List in the Company class. Furthermore I have Facade for the Company and I try to build a little client using JSPs. (The JSP is Quick'n'Dirty - refactorings are going to come).
My problem is, that when I delete an Employee from the Company, the Client acts like it is deleted, however if I check the database, the change hasn't been stored there. What do I have to do, that the changes made in the list, which is part of the company, will be passed to the database.
//button delete has been pressed
if(request.getParameter("delete") != null)
{
//since it is a list, the amount of elements in the list is passed to this JSP
int empSize = Integer.parseInt(request.getParameter("empSize"));
//All list elements are checked if they are supposed to be deleted
for(int i = 0; i < empSize; i++)
{
//just the marked list element will be deleted
if(request.getParameter("check"+i) != null)
{
employees.remove(i);
}
}
//the new list with the employees will be stored in the company instance
company.setEmps(employees);
//the facade pattern merges thes new and the old company (or it doesn't)
compFacadeRemote.edit(company);
}
And there is the Facade - nothing fancy here
@Stateless(mappedName="jms/CompanyFacade")
public class companyFacade implements companyFacadeRemote {
@PersistenceContext
private EntityManager em;
public void create(Company company) {
em.persist(company);
}
public void edit(Company company) {
em.merge(company);
em.flush();
}