I have a method in my controller which accepts a list of Employee as arguments. They are the updated objects which I want to update to the DB.
public static void save(Project project, List<ClientEmployee> clientEmployees){
...
//project is currently associated with current hibernate session.
//no clientEmployees are associated with current session, however all have id's.
for(ClientEmployee newClientEmployee : clientEmployees){
if(newClientEmployee != null){
ClientEmployee clientEmployee = JPA.em().merge(newClientEmployee);
//clientEmployee.role = newClientEmployee.role;
project.addClientEmployee(clientEmployee);
}
}
}
When I call merge, the returned object clientEmployee
does not have the updated information from newClientEmployee
. Why is that? From what I know, hibernate will try to find object with same identifier, and load it after copying fields over?
So I thought it might be that the information is only updated after I save. But even after project.save();
It does not update the object nor the row in the db.
Example..
clientEmployee.name = "John Snow"; //Current id = 1, not attached to session.
ClientEmployee persitedEmployee = JPA.em().merge(clientEmployee) //DB row has id 1, but name is null
At this point persitedEmployee.name
is still null.