You are here: Platform Specific Issues > Disconnected Objects > Comparison Of Different IDs > Example db4o UUID

Example db4o UUID

This example demonstrates how you can use db4o-UUIDs to identify objects across objects containers. Take a look advantages and disadvantages of db4o-UUIDs: See "Comparison Of Different IDs"

First you need to enable db4o-UUIDs in order to use it.

configuration.File.GenerateUUIDs = ConfigScope.Globally;
Db4oUuidExample.cs: db4o-uuids need to be activated
configuration.File.GenerateUUIDs = ConfigScope.Globally
Db4oUuidExample.vb: db4o-uuids need to be activated

With UUIDs turned on, db4o will create an UUID for each stored object. So you can get the UUID of the object from the object-container.

Db4oUUID uuid = container.Ext().GetObjectInfo(obj).GetUUID();
Db4oUuidExample.cs: get the db4o-uuid
Dim uuid As Db4oUUID = container.Ext().GetObjectInfo(obj).GetUUID()
Db4oUuidExample.vb: get the db4o-uuid

Getting a object by its UUID is also easy. First you get the object from the container. Unlike queries this won't activate your object. So you have to do it explicitly.

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);
Db4oUuidExample.cs: get an object by a db4o-uuid
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)
Db4oUuidExample.vb: get an object by a db4o-uuid