Hi,

I'm trying to port the article written by Nick Johnson on distributed
transactions from python to java:

    http://blog.notdot.net/2009/9/Distributed-Transactions-on-App-Engine

it is almost working, just have a problem on one of the last steps
where a named-key is supposed to be created.

  public static void rollForward(PersistenceManager pm, Transfer
transfer)
      throws Exception
  {
      Key namedKey = KeyFactory.createKey(
        transfer.getTargetKey(),
        Transfer.class.getSimpleName(),
        KeyFactory.keyToString(transfer.getKey()));

      ...

      Transfer destTransfer = new Transfer();
      destTransfer.setKey(namedKey);
      // destTransfer.setParentKey(); <- commented out on purpose.
      pm.makePersistent(destTransfer);
      ...
  }

when saving the destTransfer object to the datastore, I get this
error:

  "Cannot set both the primary key and a parent pk field.  If you want
the datastore to generate an id for you, set the parent pk field to be
the value of your parent key and leave the primary key field blank.
If you wish to provide a named key, leave the parent pk field blank
and set the primary key to be a Key object made up of both the parent
key and the named child.

I'm trying to take option #2, I believe I am doing it correctly. This
is the Transfer class:

  @PersistenceCapable
  public class Transfer {

      @PrimaryKey
      @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
      private Key mKey;

      @Persistent
      @Extension(vendorName="datanucleus", key="gae.parent-pk",
value="true")
      private Key mKeyParent;
 }

so in the above, I leave mKeyParent null and explicitly set mKey to
the named key value before saving it, but I'm still getting that
exception thrown.

I realize this is a bit long, does anyone see what the problem could
be? I'd like to post this port of the distributed transactions for the
group's reference once it's done, I just would like to get it actually
working first,

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appeng...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to