Dear group, Would you mind asking the reason why, in owned one-to-many relationship, parent filed in child object which is obtained via query becomes null? That is actually asked at the below posts, but I did not see the answer. http://groups.google.com/group/google-appengine-java/browse_frm/thread/28d9c3b99df25e43/8d9443f3f16635dc?lnk=gst&q=mappedby+child+object+null+parent+field#8d9443f3f16635dc http://groups.google.com/group/google-appengine-java/browse_frm/thread/ae89672a9c68fcac/b17fe3358d5bf8e0?lnk=gst&q=mappedby+child+object+null+parent+field#b17fe3358d5bf8e0
By using the Book class and Chapter class from http://groups.google.com/group/google-appengine-java/browse_frm/thread/28d9c3b99df25e43/8d9443f3f16635dc?lnk=gst&q=mappedby+child+object+null+parent+field#8d9443f3f16635dc: public void testRelation() throws Exception { Book b = new Book(); b.title = "JDO 4eva"; Chapter c1 = new Chapter(); c1.title = "Intro"; c1.numPages = 10; b.chapters.add( c1); Chapter c2 = new Chapter(); c2.title = "Configuration"; c2.numPages = 9; b.chapters.add( c2); pm = pmf.getPersistenceManager(); pm.setDetachAllOnCommit( true); pm.currentTransaction().begin(); try { pm.makePersistent( b); pm.currentTransaction().commit(); assertEquals( b, c1.book); assertEquals( b, c2.book); } finally { if (pm.currentTransaction().isActive()) { pm.currentTransaction().rollback(); } pm.close(); } // Confirm on child field in parent object pm = pmf.getPersistenceManager(); Query query = pm.newQuery( Book.class); List<Book> bookList = (List<Book>)query.execute(); // Sanity check on book assertEquals( 1, bookList.size()); Book bookEntityGroup = bookList.get( 0); assertEquals( b.title, bookEntityGroup.title); // Sanity check on chapters field assertEquals( 2, bookEntityGroup.chapters.size()); for( Chapter chapter : bookEntityGroup.chapters) { assertTrue( chapter.title.equals( c1.title) ? true : chapter.title.equals( c2.title) ? true : false ); } // for pm.close(); // Confirm on parent field in child object pm = pmf.getPersistenceManager(); query = pm.newQuery( Chapter.class); List<Chapter> chapterList = (List<Chapter>)query.execute(); assertEquals( 2, chapterList.size()); for( Chapter chapter : chapterList) { assertTrue( chapter.title.equals( c1.title) ? true : chapter.title.equals( c2.title) ? true : false ); assertNotNull( chapter.book); // This fails } // for query.close( chapterList); pm.close(); } Warm regards, Art -- 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.
