This example demonstrates how you can use UUIDs to identify objects across objects containers. Take a look advantages and disadvantages of UUIDs: See "Comparison Of Different IDs"
Don't forget to add UUID support.
This example assumes that all object have a common super class, IDHolder, which holds the UUID in a field.
private final UUID uuid = UUID.randomUUID(); public UUID getObjectId(){ return uuid; }
It's important to index the id-field, otherwise looking up for object by id will be slow.
configuration.common().add(new UuidSupport()); configuration.common().objectClass(IDHolder.class).objectField("uuid").indexed(true);
The id is hold by the object itself, so you can get it directly.
IDHolder uuidHolder = (IDHolder)obj; UUID uuid = uuidHolder.getObjectId();
You can get the object you can by a regular query.
Query query = container.query(); query.constrain(IDHolder.class); query.descend("uuid").constrain(idForObject); IDHolder object= (IDHolder) query.execute().get(0);