Question

I am trying to figure out what happens by tuning my db4o instance but this is really driving me crazy: it simply does not make sense to me.

Essentially I am creating two objects and store the first in an ArrayList of the second. Then I want to remove the first object both form the whole database and from the list where I have initially stored.

Here is a basic list of the operations I am running.

User user = new User("user");
Device device = new Device("device");
objectContainer.ext().store(user,5); // object storing depth
objectContainer.commit();

objectContainer.delete(device);

//objectContainer.close();
//objectContainer = new ...

At this point if I close and I reopen the objectContainer the user deviceList contains a null object, while if I don't close the container (as a normal running application should normally avoid) the device object is still inside the user object, while it is not in the whole database.

I just want the object to be removed from both the list and from database without any null object in place. Is this possible?? I have tried many tuning the configuration (weakReferences, activations, constraints, ...) a lot but without any success.

Was it helpful?

Solution

Why do you have the object still in the list after reopening, but not before?

  • If you delete a object, it is deleted in the database.
  • However, db4o doesn't modify any memory content. So before reopening, the collection is the 'old' in memory representation of that collection. It still contains the reference to the object. db4o won't remove it.
  • After reopening: The collection is loaded from the database. Since the object has been removed from the database, it will use a 'null' reference for the object no longer existing.

db4o won't 'remove' objects for you 'magically' from in memory object. You have to ensure that the object model has a consistent state, like any other in memory object graph.\

Here are some tips: http://community.versant.com/documentation/reference/db4o-8.1/net/reference/Content/best_practises/managing_relations.htm

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top