Check out this blog post: http://gae-java-persistence.blogspot.com/2009/10/creating-bidrectional-owned-one-to-many.html
I'm pretty sure you want to be persisting the thread and not the comment. If you make it un-owned, you want the thread to have a key and a user, then each comment has a key and a parent key which is the key of the thread it belongs to. if you do a query where parent key == thread key you should get all the comments that belong to the thread. On Feb 22, 7:06 pm, "Fernando O." <[email protected]> wrote: > tried that and it's telling me > org.datanucleus.exceptions.NucleusObjectNotFoundException: Could not > retrieve entity of kind Thread with key Thread(51) > > I also tried doing a query with the Thread key and UserKey (wich is the key > for a thread) and then I get an exception about modifying 2 entities in 1 > transaction :S > > On Tue, Feb 22, 2011 at 8:56 PM, Fernando O. <[email protected]> wrote: > > Thanks! I'll try that. BTW no, addComment does not store the comment. > > > On Tue, Feb 22, 2011 at 8:49 PM, WillSpecht <[email protected]> wrote: > > >> Don't you need to persist the thread as well as the comment? It's > >> hard to analyze your code with such a small sample. Does addComment > >> persist the thread? My > >> guess is that something is making the transaction fail, probably > >> cause you are trying to operate on two different entity groups. I > >> would simply store the comment as it's own entity and when you want > >> all the comments simply do a query for comments with parentKey == > >> ThreadKey. > > >> On Feb 21, 9:30 pm, "Fernando O." <[email protected]> wrote: > >> > Hi all. > >> > First of all I have to admit: I havent read all the docs. > > >> > I had a small app running, it basically has this: > >> > A User: > >> > @PersistenceCapable(detachable = "true") > >> > @FetchGroup(name = "_post", members = { @Persistent(name = "posts") }) > >> > public class User implements Serializable{ > >> > @PrimaryKey > >> > @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > >> > private Key key; > >> >> @Persistent(mappedBy = "user", defaultFetchGroup = "true") > >> > @Element(dependent = "true") > >> > private List<Post> posts; > >> > ....} > > >> > A thread : > > >> > @PersistenceCapable(detachable = "true") > >> > @FetchGroup(name = "_user", members = { @Persistent(name = "user")}) > >> > public class Thread implements Serializable { > >> > @PrimaryKey > >> > @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > >> > private Long key; > > >> > @Persistent(defaultFetchGroup = "true") > >> > @Element(dependent = "true") > >> > private User user; > >> > ... > > >> > } > > >> > So now I want to add comments, each comment will have: the user that > >> made > >> > the comment, and the thread that it belongs to, and some other fields: > >> > @PersistenceCapable(detachable = "true") > >> > public class ThreadComment implements Serializable{ > >> > @PrimaryKey > >> > @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > >> > private Key key; > > >> > @Persistent(defaultFetchGroup = "true") > >> > @Element(dependent = "true") > >> > private User user; > > >> > @Persistent(defaultFetchGroup = "true") > >> > @Element(dependent = "true") > >> > private Thread thread; > >> > ... > > >> > } > > >> > I changed the Thread to include a list of comments: > >> > @PersistenceCapable(detachable = "true") > >> > @FetchGroup(name = "_user", members = { @Persistent(name = > >> > "comments"),@Persistent(name > >> > = "user")}) > >> > public class Thread implements Serializable { > >> > .... > >> > @Persistent(defaultFetchGroup = "true") > >> > @Element(dependent = "true") > >> > private List<ThreadComment> comments; > > >> > } > > >> > My problem is that meanwhile this works in memory when I try to persist > >> the > >> > ThreadComment > >> > PersistenceManager pm = getPMF(); > >> > Transaction tx = pm.currentTransaction(); > >> > tx.begin(); > >> > thread.addComment(comment); > >> > pm.makePersistent(comment); > >> > tx.commit(); > >> > pm.close(); > > >> > the code gets excecuted but I don't see the comment in the database (in > >> fact > >> > the logs show no db activity either) > >> > So I don't see an exception, the code gets excecuted but I don't see the > >> > comment in the DB. > > >> > I already have the db with soem threads without comments, this is a "new > >> > feature" > > >> > Any idea of what I'm doing wrong? (please don't say everything :D ) > > >> > Thanks! > > >> > Fernando > > >> -- > >> 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. -- 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.
