tags:

views:

33

answers:

1

I wanted to know if we can have a unique identifier for all objects that are stored in ZODB

A: 

Each object stored in the ZODB does have a unique ID, accessible as its _p_oid attribute after the object has been registered:

>>> obj._p_oid

The usual caveats about primary keys apply -- if you need a unique identifier that you can continue to use even if you need to export your objects to a different database, you're better off using a uuid that you manage yourself. Python has a uuid module (in the stdlib as of Python 2.6) which can generate uuids.

David Glick
thanks for ur reply.I am maintaining a Id attribute with each class parameter.But when I'm creating dynamic objects I need to always increment it.Hence I need a way where the value doesn't get overriden in ZODB
gizgok
Having monotonically increasing ids within ZODB can be quite tricky due to ZODB's multi-version concurrency control (MVCC) feature. If you can design your app to avoid the need for it, I'd recommend that. If you do need it, I'd suggest rephrasing your question to be specifically about how to arrange for monotonically increasing ids in the ZODB.
David Glick