Out comes the ruler to whack your knuckles; you're doing your testing and 
experimenting on the dev server.

It's really quite simple to do it on your desktop if you follow their 
instructions for unit testing.  And much faster; none of that uploading, 
waiting, etc.  Make a change, recompile, right click on package or java file 
and select Run as JUnit test (in eclipse).


dataStorm wrote:
> I don't think it made a difference, if I check the online datastore it
> says "<null>" for "selectedTags". I think I am still missing
> something.
> 
> Here is my other 'tags' class, not sure if it matters for my datastore
> relationship :
> 
> 
> =======================
> 
> 
> 
>       @PrimaryKey
>       @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY,
> defaultFetchGroup="true")
>       private Key tagid;
> 
>       @Persistent(defaultFetchGroup= "true")
>       private Set<Key> selectedLinks;
> 
> 
>       @Persistent
>       private String tagname;
> 
>       @Persistent
>       private Date date;
> 
>       public Tagstore(String tagname, Date date) {
> 
>               this.tagname = tagname;
>               this.date = date;
>       }
> 
>       public Key getId() {
>               return tagid;
>       }
> 
> 
>       public String getKeyAsString() {
>       if (tagid == null) return null;
>       return KeyFactory.keyToString(tagid);
>       }
> 
> 
>       public String getTag() {
>               return tagname;
>       }
> 
>       public Date getDate() {
>               return date;
>       }
> 
>       public void setTag(String tagname) {
>               this.tagname = tagname;
>       }
> 
>       public void setDate(Date date) {
>               this.date = date;
>       }
> 
> 
> 
> 
> 
> =======================
> 
> I'm putting "defaultFetchGroup="true"" everywhere hoping it would
> help ....
> 
> 
> =======================
> 
> 
> On Nov 1, 9:11 pm, Rusty Wright <[email protected]> wrote:
>> Linkstore doesn't have a no-arg constructor does it?  If so, then 
>> selectedTags could be null.  You could change its declaration to
>>
>>         @Persistent(defaultFetchGroup = "true")
>>         private Set<Key> selectedTags = new HashSet<Key>(0);
>>
>> I've always initialized my Collections at the declaration.
>>
>> Just for experimentation, try changing its declaration to that and see what 
>> happens.
>>
>> WATCH OUT THOUGH: if you you're using eclipse you may have it configured to 
>> add a final to fields and variables that are set when they're declared and 
>> not subsequently written to.  If that happens then DataNucleus ignores final 
>> fields.  (I wish I could change some setting to have DN throw an exception 
>> in that situation.)
>>
>> dataStorm wrote:
>>> Hello, can someone help me with this, I am trying to follow this post
>>> http://code.google.com/appengine/docs/java/datastore/relationships.html
>>> to
>>> create relationship between LINKS and TAGS.
>>> I am getting an error:
>>> Caused by:
>>> java.lang.NullPointerException
>>>    at com.linkytty.Linkstore.addNewTag(Linkstore.java:101)
>>>    at com.linkytty.TagLinker.doPost(TagLinker.java:52)
>>> This happens when I try to add a key using ".add()"  :
>>> public void addNewTag(Key tagKey) {
>>> selectedTags.add(tagKey);
>>> }
>>> addNewTag() is called from my
>>> PersistenceManager pm = PMF.get().getPersistenceManager();
>>> Linkstore linkObject = pm.getObjectById(Linkstore.class, objectKey);
>>> linkObject.addNewTag(objectKey);
>>> I've logged my "objectKey" and etc. and it seems that it gets those
>>> right
>>> (
>>> String linkKeyId = req.getParameter("key");
>>> linkKeyID : aghsaW5reXR0eXIPCxIJTGlua3N0b3JlGAUM
>>> Key objectKey = KeyFactory.stringToKey(linkKeyId);
>>> objectKey: Linkstore(5)
>>> )
>>> My Classes:
>>> the class that creates links:
>>> public class Linkstore {
>>>    @PrimaryKey
>>>    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>>>    private Key linkid;
>>>    @Persistent(defaultFetchGroup = "true")
>>>    private Set<Key> selectedTags;
>>> //STUFF HERE
>>>    public Linkstore(User author, String linkcontent, String linkcomment,
>>> Date
>>> date) {
>>>            this.author = author;
>>>            this.linkcontent = linkcontent;
>>>            this.linkcomment = linkcomment;
>>>            this.date = date;
>>>            selectedTags = new HashSet<Key>();
>>>    }
>>>    public Key getId() {
>>>            return linkid;
>>>    }
>>>    public String getKeyAsString() {
>>>            if (linkid == null)
>>>                    return null;
>>>            return KeyFactory.keyToString(linkid);
>>>    }
>>>    // STUFF HERE
>>>    public void addNewTag(Key tagKey) {
>>>                    selectedTags.add(tagKey);
>>>    }
>>> }
>>> The class that captures the post:
>>>    public void doPost(HttpServletRequest req, HttpServletResponse resp)
>>>                    throws IOException {
>>>            String linkKeyId = req.getParameter("key");
>>>            Key objectKey = KeyFactory.stringToKey(linkKeyId);
>>>            String tagStringKey = req.getParameter("tagkey");
>>>            Key tagObjectKey = KeyFactory.stringToKey(tagStringKey);
>>>            PersistenceManager pm = PMF.get().getPersistenceManager();
>>>            Linkstore linkObject = pm.getObjectById(Linkstore.class, 
>>> objectKey);
>>>            linkObject.addNewTag(objectKey);
>>>            resp.sendRedirect("/");
>>>    }
>>> ///
>>> Does the "@Persistent(defaultFetchGroup = "true")" make any
>>> difference?
>>> Help & Thanks!
> > 

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