Hi Mark,
  I am not a Java guy so this is just a shot in the dark, but have you
looked into using KeyFactory.Builder to build your key?  It looks like
it will let you build the key, similar to what Nick did.

 
http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/KeyFactory.Builder.html


Robert






On Wed, Apr 28, 2010 at 1:55 AM, Mark <[email protected]> wrote:
> 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 [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/google-appengine?hl=en.
>
>

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

Reply via email to