Hi Karan, On Jun 29, 2007, at 8:20 AM, Karan Malhi wrote:
Thanks Craig, Some more follow up questions. "Anyway, the implementation is required to actually assign an id only at the point in time when you either flush the instance or ask for the object id via getObjectId. Once assigned, the id won't change." so if I do pm.makePersistent(obj); Object objectid = pm.getObjectId(obj); I am assuming JDO will assign this object an ID. lets say it is 10 What happens if I rollback the transaction?
Depends on whether the strategy is a transactional strategy. See <sequence strategy="nontransactional" for details.
If you use a contiguous transactional strategy for generating the values, the object id generator is locked from the time the id is needed until the end of the transaction. If it's noncontiguous or nontransactional, the object id generator gives unique values that will be discarded if the transaction rolls back.
Also, what happens if before I commit, some other tx uses 10 and inserts a row
Can't ever happen regardless of which strategy you use.
When I commit, will i get an exception? This would be somewhat unexpected I guess, so I think I did not understand it properly"The assignment of the object id depends to a large extent on the user's metadata for the class. Several strategies can be used." Where exactly in the metadata do I specify this?
For datastore identity, it's in the <datastore-identity strategy="sequence" metadata. Other strategies can be used.
For application identity, you would use the <field value- strategy="sequence" on the primary key field.
Also see <sequence metadata. Regards, Craig
Thanks for the help Regards Karan Singh ________________________________ From: Craig L Russell [mailto:[EMAIL PROTECTED] Sent: Thu 6/28/2007 8:34 PM To: Apache JDO project; JDO Expert Group Subject: Re: question Hi Karan, In JDO, an object id is like Schroedinger's cat [1]. You don't know what it is until you ask for it, or the implementation needs it. This is because in many cases, you need to round trip to the database to create the id and it's more efficient if you can defer the database trip until the transaction commits. Anyway, the implementation is required to actually assign an id only at the point in time when you either flush the instance or ask for the object id via getObjectId. Once assigned, the id won't change. Of course, there's nothing to stop the implementation from eagerly assigning the id during the makePersistent call. The assignment of the object id depends to a large extent on the user's metadata for the class. Several strategies can be used. Craig [1] http://en.wikipedia.org/wiki/Schrödinger's_cat On Jun 28, 2007, at 1:50 PM, Karan Malhi wrote:Does a persistent-new object have an objectID. If yes, then what is the value stored in that? How does JDO determine what value to store in it? -- Karan MalhiCraig Russell Architect, Sun Java Enterprise System http://java.sun.com/products/jdo 408 276-5638 mailto:[EMAIL PROTECTED] P.S. A good JDO? O, Gasp!
Craig Russell Architect, Sun Java Enterprise System http://java.sun.com/products/jdo 408 276-5638 mailto:[EMAIL PROTECTED] P.S. A good JDO? O, Gasp!
smime.p7s
Description: S/MIME cryptographic signature
