ObjectDB ObjectDB

ID format in objectdb 2.x for JDOHelper.getObjectId



I am trying to upgrade the objectdb from 1.x to 2.x. I installed and configured as per object db tuotrial. I am just wondering, in objectdb 1.x, when i am tring to get the object id for a persistable object, i am getting an integer as a result


Object obj = JDOHelper.getObjectId(logTestRunImpl) used to return suppose 1

obj.toString() = 1

but the same code when i am trying to execute for the same object in object db 2.x, i am getting

Object obj = JDOHelper.getObjectId(logTestRunImpl)

obj.toString() = 3:1 , which is not an integer and this object has two feild object id and type id.

Can you please let me know if there is any change in the JDOHelper.getObjectId method from object db 1.x to 2.x. And how can i just get the object id without type id.




In ObjectDB 1.x object IDs where always unique long numbers, so these numbers could represent objects uniquely without a type.

ObjectDB 2.x, on the other hand, supports many other types of object IDs (primary keys), and consequently, objects are represented uniquely by the combination of (type, object ID).

You should be able to get the number by casting the object ID (which is returned from JDOHelper.getObjectId) to LongIdentity.

Another option, you can add to your class an ID field:

    private @Id @GeneratedValue long id; // JPA code

and then the ID will be injected automatically to your objects, and you will not have to use JDOHelper.getObjectId.

ObjectDB Support

I am usingh JDO and the object which I am getting is om.objectdb.OID not LongIdentity.

I tried adding private @Id @GeneratedValue long id; but i think it only works in case of JPA not with JDO. Do you the any other mechanism for adding some annotation in the code.


You are right, actually the first solution depends on the second solution, i.e. you have to add an ID field anyway:

    private long id;

This should work also with JDO, because you may mix JPA with JDO when using ObjectDB.

I think that in pure JDO it should be:

    @Persistent(valueStrategy = IdGeneratorStrategy.NATIVE)
    private long id;


ObjectDB Support


To post on this website please sign in.