The db4o team recommends not to use object IDs where it is not necessary. db4o keeps track of object identities in a transparent way, by identifying "known" objects on updates. See "Identity Concept"
If you really need to have ids for you're object, take a look at this comparison. See "Comparison Of Different IDs"
Each object, except value objects like ints, floats or string, do have an internal id. This id is unique within on db4o database and db4o uses it internally for managing the objects. However you also can access this id or retrieve objects by the internal id.
You can get the internal id of an object from the extended object container.
long interalId = container.Ext().GetID(obj);
Dim interalId As Long = container.Ext().GetID(obj)
And you can retrieve an object by the internal id. Note that when you get an object by its internal id that it won't be activated. Therefore you have to explicitly activate the object.
long internalId = idForObject; object objectForID = container.Ext().GetByID(internalId); // getting by id doesn't activate the object // so you need to do it manually container.Ext().Activate(objectForID);
Dim internalId As Long = idForObject Dim objForID As Object = container.Ext().GetByID(internalId) ' getting by id doesn't activate the object ' so you need to do it manually container.Ext().Activate(objForID)
db4o can also generate a UUIDs for each object. The UUIDs main purpose is to enable replication. By default db4o doesn't assign a UUID to each object. You have to enable this globally or for certain types. For example:
IEmbeddedConfiguration configuration = Db4oEmbedded.NewConfiguration(); configuration.File.GenerateUUIDs = ConfigScope.Globally;
Dim configuration As IEmbeddedConfiguration = Db4oEmbedded.NewConfiguration() configuration.File.GenerateUUIDs = ConfigScope.Globally
A db4o UUID consists of two parts. The first part is the database signature which is unique to the database.
The second part a unique id within the object-container for the object. Both parts together represent a unique id.
You can get the db4o uuid from the extended object container.
Db4oUUID uuid = container.Ext().GetObjectInfo(obj).GetUUID();
Dim uuid As Db4oUUID = container.Ext().GetObjectInfo(obj).GetUUID()
And you can get an object by its UUID. Note that when you get an object by its UUIDthat it won't be activated. Therefore you have to explicitly activate the object.
object objectForId = container.Ext().GetByUUID(idForObject); // getting by uuid doesn't activate the object // so you need to do it manually container.Ext().Activate(objectForId);
Dim objForId As Object = container.Ext().GetByUUID(idForObject) ' getting by uuid doesn't activate the object ' so you need to do it manually container.Ext().Activate(objForId)