I am using embeddable version of db4o 8.1. The issue is when I retrieve an object and just call set of a property, it seems to be persisting the value in cache and subsequent retrieval gives me the same reference even when I try to retrieve by ID.
The following code is used to retrieve the object from db.
public Customer retrieveCustomer(final String id) {
ObjectContainer db = getDataSource();
Customer customer = null;
try {
List<Customer> result = db.query(new Predicate<Customer>() {
private static final long serialVersionUID = 1L;
public boolean match(Customer pilot) {
return pilot.getId().equalsIgnoreCase(id);
}
});
if (result.size() > 0) {
customer = result.get(0);
}
}
catch (Exception e) {
logger.error("Internal db failed to retrieve the object.", e);
}
return customer;
}
And somewhere in code I do setName("xyz"); from original value of "abc" and I don't do commit anywhere.
customer.setName("xyz"); // no commit or store
Everything is fine here but when the object is retrieved again from db it gives me xyz instead of "abc" as i didn't store or commit the previous object.
When I restart the server ( close and open the db ) the old value is restored
Please help.