Hari, thank you for your input.
However, I'm not looking for the work around like you suggested to do
like pm.makePersistentAll( b.getChapters()). (by the way, you didn't
mean to do like pm.makePersistentAll( b.getChapters().get( 0),
right?)

The thing is that I like to know JDO and appengine's datastore better.
If I have the wrong concepts of those in my mind, then of cause I'm
going to spend my precious time for writing codes what are not going
to work and going to have trouble, right? (And having and already had
enough trouble, actually. ;-)) Also, it doesn't feel good to write
code like "if I write this way, then it doesn't work, but write other
way, mysteriously works." ;-)

Back to subject: interestingly enough, if I added the codes to get the
targeted chapter object by getObjectById, detach it, change it, and
persist it, then, after that, the previously failing unit test part
passed. Why? Is there the known and open issue for this? Or I'm
missing something like usual. ;-)

        prepTestObjects();

        Chapter detachedChapter;

        // Inserting the codes below misteriously made the following unit
test pass. ----------------------
        pm = pmf.getPersistenceManager();
        Chapter chapter =
                (Chapter)pm.getObjectById( Chapter.class,
b.getChapters().get( 0).getEncodedKey());
        detachedChapter = (Chapter)pm.detachCopy( chapter);
        pm.close();
        int numPages = detachedChapter.getNumPages();
        detachedChapter.setNumPages( numPages + 1);
        pm = pmf.getPersistenceManager();
        pm.makePersistent( detachedChapter);
        pm.close();
        pm = pmf.getPersistenceManager();
        chapter =
                (Chapter)pm.getObjectById( Chapter.class,
b.getChapters().get( 0).getEncodedKey());
        detachedChapter = (Chapter)pm.detachCopy( chapter);
        pm.close();
        assertEquals( numPages + 1, detachedChapter.getNumPages());
        //
------------------------------------------------------------------------------------------------
        int originalNumPages = b.getChapters().get( 0).getNumPages();
        do {
                b.getChapters().get( 0).setNumPages(
                                new Double( Math.round( Math.random() * 
99)).intValue() + 1
                                );
        } while( originalNumPages == b.getChapters().get( 0).getNumPages());
        int newNumPages = b.getChapters().get( 0).getNumPages();


        pm = pmf.getPersistenceManager();
        pm.makePersistent( b.getChapters().get( 0));
        detachedChapter = (Chapter)pm.detachCopy( b.getChapters().get( 0));
        pm.close();
//This failed before inserting codes above, but now it pass. Why?
        assertEquals( newNumPages, detachedChapter.getNumPages());




On Jul 30, 8:45 pm, Hariharan Anantharaman
<hariharan.ananthara...@gmail.com> wrote:
> Hi,
> Try using the method makePersistentAll. I too faced similar issue and using
> the all method worked fine.
>
> ~hari
>
> On Jul 31, 2010 6:07 AM, "Art" <art...@gmail.com> wrote:
>
> Dear group,
>
> I would like to know the reason why child value won't be stored when
> it's persisted directly by referring as a element of list field of
> parent.
> In the next testDetach7 JUnit test (which tries to change the value of
> existing child entity field),
>    - chapter child object was not stored by persisting like
> pm.makePersistent( b.getChapters().get( 0))
>    - chapter child object was stored by persisting the parent like by
> pm.makePersistent( b);
>
>        public void testDetach7() throws Exception {
>                prepTestObjects();
>
>                int originalNumPages = b.getChapters().get( 0).getNumPages();
>                do {
>                        b.getChapters().get( 0).setNumPages(
>                                        new Double( Math.round( Math.random()
> * 99)).intValue() + 1
>                                        );
>                } while( originalNumPages == b.getChapters().get(
> 0).getNumPages());
>                int newNumPages = b.getChapters().get( 0).getNumPages();
>
> /*
>                pm = pmf.getPersistenceManager();
>                pm.makePersistent( b.getChapters().get( 0));
>                Chapter detachedChapter =
> (Chapter)pm.detachCopy( b.getChapters().get( 0));
>                pm.close();
> This fails
>                assertEquals( newNumPages, detachedChapter.getNumPages());
> */
>
>                pm = pmf.getPersistenceManager();
>                pm.makePersistent( b);
>                Chapter detachedChapter =
> (Chapter)pm.detachCopy( b.getChapters().get( 0));
>                pm.close();
> // This will pass
>                assertEquals( newNumPages, detachedChapter.getNumPages());
>
>        }
>
>        protected void prepTestObjects() throws Exception {
>                b = new Book();
>                b.setTitle( "JDO 4eva");
>
>                c1 = new Chapter();
>                c1.setTitle( "Intro");
>                c1.setNumPages( 10);
>
>                b.getChapters().add( c1);
>
>                c2 = new Chapter();
>                c2.setTitle( "Configuration");
>                c2.setNumPages( 9);
>                b.getChapters().add( c2);
>
>                pm = pmf.getPersistenceManager();
>                pm.setDetachAllOnCommit( true);
>                try {
>                        pm.currentTransaction().begin();
>                    pm.makePersistent( b);
>                    pm.currentTransaction().commit();
>                } finally {
>                    if (pm.currentTransaction().isActive()) {
>                        pm.currentTransaction().rollback();
>                    }
>                    pm.close();
>                }
>        }
>
> /**
>  * 
> Fromhttp://gae-java-persistence.blogspot.com/2009/10/creating-bidrectiona...
>  */
> @PersistenceCapable(identityType = IdentityType.APPLICATION,
> detachable = "true")
> public class Book {
>
>        // Prefer String encodedKey over Key class object since it's sharable
> with client via serialization
>   �...@primarykey
>   �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>       �...@extension( vendorName = "datanucleus", key = "gae.encoded-pk",
> value="true")
>        protected String encodedKey;
>
>        protected String title;
>
>   �...@persistent(mappedBy = "book", defaultFetchGroup="true")
>   �...@element( dependent = "true")
>    protected List<Chapter> chapters = new ArrayList<Chapter>();
>
>    - getter and setters -
>
> }
>
> @PersistenceCapable( identityType = IdentityType.APPLICATION,
> detachable = "true")
> public class Chapter {
>        // Prefer String encodedKey over Key class object since it's sharable
> with client via serialization
>   �...@primarykey
>   �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>       �...@extension( vendorName = "datanucleus", key = "gae.encoded-pk",
> value="true")
>        protected String encodedKey;
>
>    protected String title;
>    protected int numPages;
>
>   �...@persistent( defaultFetchGroup = "true")
>    protected Book book;
>
>    - getter and setters -
>
> }
>
> --
> 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<google-appengine-java%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group 
> athttp://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 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