Problems with DB4O on Android - Update objects

624 views Asked by At

I have a problem when I try to update my persistences objects.

I retrive my objects using.

objectContainer.query(myObject);

modified and save again using:

objectContainer.store(myObject);

But this object don't update, just save another object.

I tried get object using:

long idObject = objectContainer.ext().getID(myObject);

objectContainer.ext().getById(idObject);

But ocurred same problem. Somebody know whats happens?

Thanks, sorry my english.

1

There are 1 answers

0
Gamlor On

Did you close the object container between loading the object and calling objectContainer.Store(myObject)? To me it looks like you are not using the same object-container instance to load and store the object.

db4o recognized objects by their identity. To achieve that the object container has a map which remembers all loaded objects. When you call store, db4o looks up in that map if it is an existing object. If so, it updates that object. Otherwise it assumes that the object is a new one.

To fix the issue: Don't close the object-container, but rather keep it open. If thats not an option, you need to load the object from the database and merge it with the object containing the changes.

If this answer doesn't solve you issue, let me know =)