Hello Aswath,

What you are doing seems really odd to me. From my understanding a
Datastore Key consists of multiple components.
"A complete key includes several pieces of information, including the
application ID, the kind, and an entity ID" - GAE Docs

If you use encoded key strings, you can get access to these other
pieces of information:
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName="datanucleus", key="gae.encoded-pk",
value="true")
private String encodedKey;

@Persistent
@Extension(vendorName="datanucleus", key="gae.pk-name", value="true")
private String keyName;

@Persistent
@Extension(vendorName="datanucleus", key="gae.pk-id", value="true")
private Long keyId;

In this case, you have access to the name ID (keyName) and numeric ID
(keyID) of the encoded key. Therefore, from my understanding, you can
not change the name ID after you have persisted your first object. The
first object determines the name ID for all remaining objects (from my
understanding). This is why when you try to change it for the second
object, you get an exception.

Perhaps, you can better explain why you are using the "gae.pk-name"
extension for the name. The context of your code is not clear!

Thanks!


On Feb 16, 11:38 pm, aswath satrasala <[email protected]>
wrote:
> any help on this please...
>
> Thanks.
>
> On Fri, Feb 12, 2010 at 3:18 PM, aswath satrasala <
>
>
>
> [email protected]> wrote:
> > Hello Ikia
> > As suggested by you in the thread 'Incorrect number of entities returned',
> > I have attached the complete files in my previous email.
> > Please let me know, what am I doing wrong here.
>
> > Thanks
> > -Aswath
>
> > On Tue, Feb 9, 2010 at 3:06 PM, aswath satrasala <
> > [email protected]> wrote:
>
> >> Hello Ikai,
> >> Attached is the zip file that contains three files
> >> A.java
> >> B.java
> >> BTest.java
>
> >> Please load in your environment and test it.
>
> >> Thanks.
> >> -Aswath
>
> >> On Fri, Feb 5, 2010 at 4:36 PM, aswath satrasala <
> >> [email protected]> wrote:
>
> >>> B list is missing from class A in my previous posting.  Here is the
> >>> complete A class...
>
> >>> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> >>> public class A {
> >>>     @PrimaryKey
> >>>     @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
> >>>     @Extension(vendorName = "datanucleus", key="gae.encoded-pk",
> >>> value="true")
> >>>     private String id;
>
> >>>     @Persistent
> >>>     @Extension(vendorName = "datanucleus", key="gae.pk-name",
> >>> value="true")
> >>>     private String name;
>
> >>>     @Persistent
> >>>     private List<B> bList ;
>
> >>> }
>
> >>> On Fri, Feb 5, 2010 at 4:32 PM, aswath satrasala <
> >>> [email protected]> wrote:
>
> >>>> This is a similar posting I had posted earlier "incorrect number of
> >>>> entities returned".  Hopefully, this posting may be more clean and I will
> >>>> get some replies.
> >>>> I have two classes
> >>>> 1) A
> >>>> 2) B
> >>>> A is in 1 to many relationship with B
> >>>> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> >>>> public class A {
> >>>>     @PrimaryKey
> >>>>     @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
> >>>>     @Extension(vendorName = "datanucleus", key="gae.encoded-pk",
> >>>> value="true")
> >>>>     private String id;
>
> >>>>     @Persistent
> >>>>     @Extension(vendorName = "datanucleus", key="gae.pk-name",
> >>>> value="true")
> >>>>     private String name;
> >>>> }
>
> >>>> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> >>>> public class B {
> >>>>     @PrimaryKey
> >>>>     @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
> >>>>     @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value
> >>>> = "true")
> >>>>     private String id;
>
> >>>>     @Persistent
> >>>>     @Extension(vendorName = "datanucleus", key = "gae.pk-name", value =
> >>>> "true")
> >>>>     private String name;
> >>>> }
>
> >>>> public class BTest extends JDOTestCase {
>
> >>>>     public void testB() throws Exception {
> >>>>         A a = new A();
> >>>>         a.setName("a");
> >>>>         B b = new B();
> >>>>         b.setName("b");
> >>>>         a.getBList().add(b);
>
> >>>>         beginTxn();
> >>>>         pm.makePersistent(a);
> >>>>         a = pm.getObjectById(A.class, a.getId());
> >>>>         assertEquals(1, a.getBList().size());
> >>>>         commitTxn();
>
> >>>>         B b1 = new B();
> >>>>         b1.setName("b1");
> >>>>         beginTxn();
> >>>>         pm.makePersistent(b1);
> >>>>         b1 = pm.getObjectById(B.class, b1.getId());
> >>>>         b1.getId();
> >>>>         commitTxn();
> >>>>     }
> >>>> }
>
> >>>> The test fails at the last line "b1.getId()"
> >>>> If any of B entity is in relation with A earlier, then another entity of
> >>>> B cannot be persisted by itself.
>
> >>>> If I move the 2nd transaction to the beginning, the test passes.
>
> >>>> -Aswath

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" 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-java?hl=en.

Reply via email to