I followed the documentation on Keys:
http://code.google.com/appengine/docs/java/datastore/creatinggettinganddeletingdata.html#Keys
>From my understanding the annotation is used to tell the datastore to
use the name property to generate the key if it's populated. Maybe I
misinterpreted the documentation.

On Jan 27, 11:47 pm, Rusty Wright <[email protected]> wrote:
> Yes, as you can surmise, I'm guessing.
>
> What's this annotation on the name property for?
>
> @Extension(vendorName="datanucleus", key="gae.pk-name", value="true")
>
>
>
>
>
> Sydneywrote:
> > Since I declared the parameter with query.declareParameters("String
> > nameParam");, the colon is not valid. As expected I got an exception
> > org.datanucleus.store.query.QueryCompilerSyntaxException: Explicit
> > parameters defined for query, yet implicit parameter syntax
> > (":nameParam") found
>
> > On Jan 27, 4:39 pm, Rusty Wright <[email protected]> wrote:
> >> Do you need a colon in front of nameParam?
>
> >>             query.setFilter("name == :nameParam");
>
> >> Sydneywrote:
> >>> The query returns no result.
> >>>             ApiProxy.setEnvironmentForCurrentThread(new TestEnvironment
> >>> ());
> >>>             ApiProxy.setDelegate(new ApiProxyLocalImpl(new File("."))
> >>> {
> >>>             });
> >>>             A a = new A("A");
> >>>             B b = new B("B");
> >>>             a.getBs().add(b);
> >>>             PersistenceManagerFactory pmf =
> >>> JDOHelper.getPersistenceManagerFactory("transactions-optional");
> >>>             PersistenceManager pm = pmf.getPersistenceManager();
> >>>             Transaction tx = pm.currentTransaction();
> >>>             try {
> >>>                 tx.begin();
> >>>                 pm.makePersistent(a);
> >>>                 tx.commit();
> >>>             } finally {
> >>>                 if (tx.isActive()) {
> >>>                     tx.rollback();
> >>>                 }
> >>>             }
> >>>             System.out.println(a.getKey());
> >>>             A ap = pm.getObjectById(A.class, "A");
> >>>             System.out.println(ap.getKey());
> >>>             Query query = pm.newQuery(B.class);
> >>>             query.setFilter("name == nameParam");
> >>>             query.declareParameters("String nameParam");
> >>>             List<B> rs = (List<B>) query.execute("B");
> >>>             System.out.println(rs.size());
> >>> On Jan 23, 12:20 am, John Patterson <[email protected]> wrote:
> >>>> Execute a query on the name property of B rather than loading it by  
> >>>> key.  If the name is unique the result should only contain one B.
> >>>> On 23 Jan 2010, at 11:41,Sydneywrote:
> >>>>> I have a one to many relationship. There is a problem in the way I
> >>>>> query for a B object. I was wondering what is the best way (most
> >>>>> efficient) to do that.
> >>>>> A a = new A("A");
> >>>>> B b = new B("B");
> >>>>> a.getBs().add(b);
> >>>>> pm.makePersistent(a); // it's done inside a transaction
> >>>>> A ap = pm.getObjectById(A.class, "A"); // FINE
> >>>>> B bp = pm.getObjectById(B.class, "B"); // NOT FOUND Exception
> >>>>> I guess B is not found because the real key is not B but B + A key.
> >>>>> How do you get the B object when you don't know nothing about A?
> >>>>> public class A {
> >>>>>   �...@primarykey
> >>>>>   �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
> >>>>>   �...@extension(vendorName = "datanucleus", key = "gae.encoded-pk",
> >>>>> value = "true")
> >>>>>    private String key;
> >>>>>   �...@persistent
> >>>>>   �...@extension(vendorName = "datanucleus", key = "gae.pk-name", value
> >>>>> = "true")
> >>>>>    private String name;
> >>>>>   �...@persistent(mappedBy = "a")
> >>>>>    private List<B> bs;
> >>>>>    public A(String name) {
> >>>>>        this.name = name;
> >>>>>        bs = new ArrayList<B>();
> >>>>>    }
> >>>>> ... Getter/Setter
> >>>>> }
> >>>>> @PersistenceCapable(identityType =
> >>>>> javax.jdo.annotations.IdentityType.APPLICATION)
> >>>>> public class B {
> >>>>>   �...@primarykey
> >>>>>   �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
> >>>>>   �...@extension(vendorName = "datanucleus", key = "gae.encoded-pk",
> >>>>> value = "true")
> >>>>>    private String key;
> >>>>>   �...@persistent
> >>>>>   �...@extension(vendorName = "datanucleus", key = "gae.pk-name", value
> >>>>> = "true")
> >>>>>    private String name;
> >>>>>   �...@persistent
> >>>>>    private A a;
> >>>>>    public B(String name) {
> >>>>>        this.name = name;
> >>>>>    }
> >>>>> ... Getter/Setter
> >>>>> }
> >>>>> --
> >>>>> 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 
> >>>>> athttp://groups.google.com/group/google-appengine-java?hl=en
> >>>>> .
>
> --
> 0x2B | ~0x2b  --  Hamlet

-- 
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