Hi Robert,
I gave that method a shot too, same error though, this is how I used
it:
Key namedKey =
new KeyFactory.Builder(
transfer.getTargetKey())
.addChild(
Transfer.class.getSimpleName(),
KeyFactory.keyToString(transfer.getKey())).getKey();
and I am still leaving mKeyParent null, as directed by the error
message.
I think I could create my own transfer class to effectively do the
same thing without all these keys, but I wanted to try doing a one-to-
one port of Nick's code first before applying any creative variations
on it. I'll try to dig around a bit more today,
Thank you!
On Apr 28, 7:21 am, Robert Kluin <[email protected]> wrote:
> 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/appengi...
>
> 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
> > athttp://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
> athttp://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.