In the test case, tests 1 and 3 are basically the same scenario, except that
in test 1 the object is detached, while in test 3 I still work with the
attached object. And test 1 fails, while test 3 passes.

    /** Failing test */
    @Test
    public void testBasicPlayerRankingPersistence() {
        PersistenceManager pm = this.newPersistenceManager();

        // Create the first instance. In our case, when the player creates
an
        // account.
        final Player player = new Player("hop");
        final Player testPlayer = pm.makePersistent(player);
        final Player detached = pm.detachCopy(testPlayer);
        pm.close();

        pm = this.newPersistenceManager();
        final Ranking ranking = new Ranking(1000, 200);
        detached.setRanking(ranking);

        final Player testPlayer2 = pm.makePersistent(detached);
        final Player detached2 = pm.detachCopy(testPlayer2);
        // Exception raised here
        pm.close();

        assertNotNull("testPlayer2 ID should not be null",
detached2.getId());
    }

    /** This test is ok */
    @Test
    public void testBasicPlayerRankingPersistence3() {
        PersistenceManager pm = this.newPersistenceManager();

        final Player player = new Player("hop");
        final Player testPlayer = pm.makePersistent(player);
        pm.close();

        pm = this.newPersistenceManager();

        final Ranking ranking = new Ranking(1000, 200);
        testPlayer.setRanking(ranking);
        final Player testPlayer2 = pm.makePersistent(testPlayer);
        pm.close();

        assertNotNull("testPlayer2 ID should not be null",
testPlayer2.getId());
    }

If I set the DetachAllOnCommit property to true, both tests fail.

Thanks in advance for any hint you may be able to offer.
-- 
seb


2011/7/8 Sébastien Tromp <[email protected]>

> Hello,
>
> Thanks for your answer. My question was really to understand why the tests
> included are failing. As far as I understand, there is no parent defined in
> my Ranking entity, so I expect the Player to which it belongs to be created
> when the Player is being persisted.
>
> I have included the core of the test (the tests themselves, and the
> annotated model objects).
> --
> seb
>
>
> 2011/7/8 Christopher Merrill <[email protected]>
>
>> It is not clear (to me) exactly what question you are asking. Are you
>> asking if it is possible to change the parent of a datastore entity
>> after it has been created? AFAIK, the answer is no, because the parent
>> is an inherent part of the identity of the entity...which also cannot
>> be changed. You have to create a new entity with the new parent,
>> delete the old, and update all references to the old entity to point
>> at the new one.
>>
>> As far as your code example, many people (including myself) are not
>> going to download and open a zip file from unknown sources.  You will
>> get a better response by including the smallest possible code snippet
>> that shows exactly the problem you are trying to solve.
>>
>> Chris
>>
>>
>> 2011/7/7 Sébastien Tromp <[email protected]>:
>> > Hello,
>> > I have already posted this e-mail on the general AppEngine google group,
>> but
>> > without any answer; so I assume it may be better suited in the AppEngine
>> for
>> > Java group.
>> > -----------
>> > Hello,
>> > First of all I'd like to apologize, because it seems that this question
>> has
>> > been asked several times already. I looked at them all, but
>> unfortunately
>> > couldn't find the answer to my issue.
>> > I have put together the attached test case to illustrate my issue, but
>> to
>> > sum it up:
>> > - I create a Player entity
>> > - I create a Ranking entity
>> > - I assign the Ranking to the Player
>> > - I persist the player
>> > And at that point the aforementioned exception is raised.
>> > The attached test case contains all the details for the classes, and
>> should
>> > be self-sufficient provided the classpath is properly configured.
>> > If, in my parent class (Player), when I set the child (Ranking), I do:
>> > public void setRanking(final Ranking ranking) {
>> >         this.ranking = ranking;
>> >         ranking.setPlayer(this);
>> >     }
>> > all tests seem to pass, except for the last one. And it really looks
>> like a
>> > hack to me, so I'm not sure that's the way to go.
>> > I'd be glad to give any additional information I may have forgotten, or
>> > pointers to the documentation that explains what I did wrong (there is
>> > obviously something I'm not getting here).
>> > Thanks in advance for your help,
>> > --
>> > Seb
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Google App Engine for Java" group.
>> > To view this discussion on the web visit
>> > https://groups.google.com/d/msg/google-appengine-java/-/YIWXRkvgjs0J.
>> > 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.
>>
>>
>
>
> --
> Seb
>
>


-- 
Seb

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