No, no caught or uncaught exception what so ever.

I tried to create a very simple version of what I was doing. The
simplest example, I could imagine, is the following:

public class OwnedRelationships extends LocalServiceTestCase {

        @PersistenceCapable(identityType = IdentityType.APPLICATION)
        static class Parent {

                @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
                @PrimaryKey
                Key key;

                @Persistent
                Child child;

                @Persistent
                String value;
        }

        @PersistenceCapable(identityType = IdentityType.APPLICATION)
        static class Child {
                @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
                @PrimaryKey
                Key key;

                @Persistent
                String value;
        }

        public void testOneToOne() {
                PersistenceManager pm = PMF.get().getPersistenceManager();

                Parent parent = new Parent();
                Child child = new Child();
                parent.value = "parent1";
                child.value = "child1";
                parent.child = child;

                try {
                        pm.makePersistent(parent);
                } finally {
                        pm.close();
                }

                pm = PMF.get().getPersistenceManager();
                Parent controlParent = null;
                try {
                        controlParent = pm.getObjectById(Parent.class, 
parent.key);
                } finally {
                        pm.close();
                }

                assertTrue(controlParent.child != null);  // some times
controlParent.child is null, sometimes it is not
                assertTrue(controlParent.child.equals("child1"));
        }
}

This simple example, actually never works. But I think it should work,
shouldn't it?

The next example, is the actual code that caused the arbitrary
behaviour. Sometimes it works, sometimes it doesn't. Once compiled, it
behaves the same way on every run. But you change it a little bit,
maybe comment some unimportant line, and it stops working.

public class DBTest extends LocalServiceTestCase {

        public void testPlayerWithComments() {
                PlayerDB player = PlayerDB.createDefault("test1");
                CommentDB comment = CommentDB.createDefault();
                comment.setAuthor(player);
                player.getComments().add(comment);

                PersistenceManager pm = PMF.get().getPersistenceManager();
                try {
                        pm.makePersistent(player);
                } finally {
                        pm.close();
                }
                pm = PMF.get().getPersistenceManager();
                try {
                        PlayerDB controlPlayerObject = 
pm.getObjectById(PlayerDB.class,
"test1");
                        assertTrue("comment not persistet in player",
controlPlayerObject.getComments().size() == 1);  // the list is
sometimes empty, even though it should contain one comment

                        CommentDB controlCommentObject = 
pm.getObjectById(CommentDB.class,
controlPlayerObject.getComments().get(0).getKey());
                        assertTrue("cannot navigate to player",
                                        
controlCommentObject.getAuthor(pm).getId().equals
(controlPlayerObject.getId()));

                        Collection<CommentDB> comments = 
(Collection<CommentDB>)pm.newQuery
(CommentDB.class).execute();
                        assertTrue("comment not loadable with query", 
comments.size() ==
1);
                } finally {
                        pm.close();
                }
        }
}

@PersistenceCapable(identityType=IdentityType.APPLICATION)
public class CommentDB {

        public static CommentDB createDefault() {
                CommentDB result = new CommentDB();
                result.setComment("");
                return result;
        }

        private CommentDB() {

        }

        @PrimaryKey
        @Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
        private Key key;

        @Persistent
        private Text comment;

        @Persistent
        private String author;

        @Persistent
        private Key owner;

        public String getComment() {
                return comment.getValue();
        }

        public void setComment(String comment) {
                this.comment = new Text(comment);
        }

        public PlayerDB getAuthor(PersistenceManager pm) {
                return pm.getObjectById(PlayerDB.class, author);
        }

        public void setAuthor(PlayerDB author) {
                this.author = author.getId();
        }

        public <T> T getOwner(PersistenceManager pm, Class<T> ownerType) {
                return pm.getObjectById(ownerType, owner);
        }

        public void setOwner(Key owner) {
                this.owner = owner;
        }

        public Key getKey() {
                return key;
        }

}

@PersistenceCapable(identityType=IdentityType.APPLICATION)
public class PlayerDB {

        @PrimaryKey
        @Persistent
        private String id;

        @Persistent
        private String nickName;

        @Persistent
        private List<SargeDB> sarges = new ArrayList<SargeDB>();

        @Persistent
        private List<CommentDB> comments = new ArrayList<CommentDB>();

        public static PlayerDB createDefault(String userId) {
                PlayerDB result = new PlayerDB();
                result.id = userId;
                return result;
        }

        public String getId() {
                return id;
        }

        public String getNickName() {
                return nickName;
        }

        public void setNickName(String nickName) {
                this.nickName = nickName;
        }

        public List<SargeDB> getSarges() {
                return sarges;
        }

        public List<CommentDB> getComments() {
                return comments;
        }

}

I am sure I misused the data store api in some way. I just don't see
how. Thanks for your time and insight.
Markus

-- 
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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to