Reputation: 235
I am using hazelcast IMap to save my objects. I get the object that I need with the get method. But, when I try to update an object attribute in the cache using the put method it doesn't seem to work. Here is the logic...
public class EmployeeEntity {
private boolean paid;
// public setters and getters
}
public class Employee extends EmployeeEntity {
private String id;
private String name;
// ... and many more
// public setters and getters
}
Load objects to IMap employeeMap with the put method() - [Key is employee.id, Value is employee object]
for (Employee employee : employeeList) {
Employee emp = employeeMap.get(employee.id)
if (!emp.isPaid()) {
emp.pay() // set the paid attribute to true
employeeMap.put(employee.id, emp)
}
}
The employeeMap has IDs
"123","456","789".
The employee list in the loop has IDs
"123","123","123","789","456","789","456".
The employee IDs repeated in the list are being paid each time instead of just for the first time.
For some reason the put() is not replacing the updated emp object.
Every time, the get method returns the object which has the paid attribute set to false.
What am I missing here?
-- Update: It worked when I changed the employee.name attribute. Seems like something to do with the superclass or the boolean type.
Upvotes: 3
Views: 1918
Reputation: 235
My superclass EmployeeEntity does not implement Serializable. So, the hazelcast wasn't serializing it when putting in cache. It worked when I implemented Serializable.
Upvotes: 3