I figured out my problem.  At least I think I did.

In my @Before annotated setup() method, instead of using the original 
platformPc variable to verify what was persisted, I need to fetch its persisted 
golem and use that.  In the code below I have a bunch of log.debugs that are 
showing the sizes of things; below that are assertions.  I changed my assertion 
for the failing test to use the persisted platformPc as follows:

        final Platform persistedPlatformPc = this.platformDao.findByName("pc");

        Assert.assertEquals("waitlistEntry list size",
                3, persistedPlatformPc.getWaitlistEntries().size());

This seems a little strange to me because I could swear that with Hibernate the 
original object was updated.  But maybe I'm misremembering that.


Rusty Wright wrote:
> with Wrigley's Doublemint gum.  In my case we're halving it at minimum.
> 
> I added mappedBy to my @Persistent annotations and now things are 
> getting into the Set twice.  Very strange.  I can't figure out what I'm 
> doing wrong.
> 
> In the following setup() I'm adding 3 WaitlistEntry objects but the Set 
> ends with 6.  The number of persisted WaitlistEntry objects is correctly 3.
> 
> Here are the relevant (I hope) bits of the usual suspects and a pretty 
> printed version of the dump of waitlistEntries that shows the duplicates.
> 
> The remaining sane parts of my brain thank you for your help.
> 
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> 
> @PersistenceCapable(identityType = IdentityType.APPLICATION, detachable 
> = "true")
> public class Platform implements Serializable, Comparable<Platform> {
> 
>    @PrimaryKey
>    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>    private Key id;
> 
>    @Persistent
>    private String name;
> 
>    @Persistent
>    private Short ordinal;
> 
>    @Persistent
>    private Facility facility;
> 
>    // mappedBy causes entries to be added twice
>    @Element(dependent = "true")
>    @Persistent(defaultFetchGroup = "true", mappedBy = "platform")
>    private Set<Host> hosts = new HashSet<Host>(0);
> 
>    // mappedBy causes entries to be added twice
>    @Element(dependent = "true")
>    @Persistent(defaultFetchGroup = "true", mappedBy = "platform")
>    private Set<WaitlistEntry> waitlistEntries = new 
> HashSet<WaitlistEntry>(0);
> 
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> 
> @PersistenceCapable(identityType = IdentityType.APPLICATION, detachable 
> = "true")
> public class WaitlistEntry implements Serializable, 
> Comparable<WaitlistEntry> {
> 
>    @PrimaryKey
>    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>    private Key id;
> 
>    @Persistent
>    private Key userKey;
> 
>    @Persistent
>    private Date entryTime;
> 
>    @Persistent
>    private Platform platform;
> 
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> test
> 
>    @Before
>    public void setup() throws Exception {
>        Assert.assertEquals("facilities entity count",
>                0, this.testUtils.entityCounter(Facility.class));
> 
>        final Facility facility = new Facility("Abc Facility", 
> this.facilityName, false);
> 
>        final Platform platformPc = new Platform("pc");
>        final Platform platformMac = new Platform("mac");
> 
>        Assert.assertEquals("waitlistEntry list size",
>                0, platformPc.getWaitlistEntries().size());
> 
>        final User user1 = new User(this.userName, Long.toString(111L));
>        final User user2 = new User(this.userName + "1", 
> Long.toString(222L));
>        final User user3 = new User(this.userName + "2", 
> Long.toString(333L));
> 
>        platformPc.addWaitlistEntry(new 
> WaitlistEntry(this.userDao.makePersistent(user1)));
>        platformPc.addWaitlistEntry(new 
> WaitlistEntry(this.userDao.makePersistent(user2)));
>        platformPc.addWaitlistEntry(new 
> WaitlistEntry(this.userDao.makePersistent(user3)));
> 
>        facility.addPlatform(platformPc);
>        facility.addPlatform(platformMac);
> 
>        final Facility persistedFacility = 
> this.facilityDao.makePersistent(facility);
> 
>        this.log.debug("waitlistEntries: {}", 
> platformPc.getWaitlistEntries());
> 
>        this.log.debug("facilities entity count: {}",
>                this.testUtils.entityCounter(Facility.class));
>        this.log.debug("user entity count: {}",
>                this.testUtils.entityCounter(User.class));
>        this.log.debug("platform list size: {}",
>                persistedFacility.getPlatforms().size());
>        this.log.debug("platform entity count: {}",
>                this.testUtils.entityCounter(Platform.class));
>        this.log.debug("waitlistEntry list size: {}",
>                platformPc.getWaitlistEntries().size());
>        this.log.debug("waitlistEntry entity count: {}",
>                this.testUtils.entityCounter(WaitlistEntry.class));
> 
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> dao
> 
>    public E makePersistent(final E entity) {
>        final E persisted = getPersistenceManager().makePersistent(entity);
> 
>        return (getPersistenceManager().detachCopy(persisted));
>    }
> 
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> model/dto/domain class
> 
>    /**
>     * @return the waitlistEntries
>     */
>    public Set<WaitlistEntry> getWaitlistEntries() {
>        this.log.debug("waitlistEntries class: {}", 
> this.waitlistEntries.getClass().getCanonicalName());
> 
>        return (Collections.unmodifiableSet(this.waitlistEntries));
>    }
> 
>    /**
>     * @param waitlistEntry
>     * @return true if added
>     */
>    public boolean addWaitlistEntry(final WaitlistEntry waitlistEntry) {
>        this.log.debug("adding: {}", waitlistEntry);
> 
>        return (this.waitlistEntries.add(waitlistEntry));
>    }
> 
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> debug dump
> 
> 2009-11-01 19:16:03.381 PST, DEBUG: [main] 
> com.objecteffects.waitlist.db.impl.dao.jdo.WaitlistEntryDaoTest.setup.90: 
> waitlistEntries:[
> com.objecteffects.waitlist.db.domain.waitlisten...@19ba1d8[
>    id=Facility(4)/Platform(6)/WaitlistEntry(7),
>    userKey=User(3),
>    entryTime=Sun Nov 01 19:16:03 PST 2009,
>    platform=com.objecteffects.waitlist.db.domain.platf...@9e75f6[
>        id=Facility(4)/Platform(6),
>        name=pc,
>        ordinal=<null>,
>        facility=com.objecteffects.waitlist.db.domain.facil...@1f82253[
>            id=Facility(4),
>            name=facility-abc,
>            fullName=Abc Facility,
>            waitlistEnabled=false,
>            platforms=[
>                com.objecteffects.waitlist.db.domain.platf...@15291cd[
>                    id=Facility(4)/Platform(5),
>                    name=mac,
>                    ordinal=<null>,
>                    
> facility=com.objecteffects.waitlist.db.domain.facil...@1f82253,
>                    hosts=[],
>                    waitlistEntries=[],
>                    jdoDetachedState=<null>
>                ],
>                com.objecteffects.waitlist.db.domain.platf...@9e75f6[
>                    id=Facility(4)/Platform(6),
>                    name=pc,
>                    ordinal=<null>,
>                    
> facility=com.objecteffects.waitlist.db.domain.facil...@1f82253,
>                    hosts=[],
>                    waitlistEntries=[
>                        
> com.objecteffects.waitlist.db.domain.waitlisten...@19ba1d8[
>                            id=Facility(4)/Platform(6)/WaitlistEntry(7),
>                            userKey=User(3),
>                            entryTime=Sun Nov 01 19:16:03 PST 2009,
>                            
> platform=com.objecteffects.waitlist.db.domain.platf...@9e75f6,
>                            jdoDetachedState=<null>
>                        ],
>                        
> com.objecteffects.waitlist.db.domain.waitlisten...@154c054[
>                            id=Facility(4)/Platform(6)/WaitlistEntry(8),
>                            userKey=User(1),
>                            entryTime=Sun Nov 01 19:16:03 PST 2009,
>                            
> platform=com.objecteffects.waitlist.db.domain.platf...@9e75f6,
>                            jdoDetachedState=<null>
>                        ],
>                        
> com.objecteffects.waitlist.db.domain.waitlisten...@148c02f[
>                            id=Facility(4)/Platform(6)/WaitlistEntry(9),
>                            userKey=User(2),
>                            entryTime=Sun Nov 01 19:16:03 PST 2009,
>                            
> platform=com.objecteffects.waitlist.db.domain.platf...@9e75f6,
>                            jdoDetachedState=<null>
>                        ],
>                        
> com.objecteffects.waitlist.db.domain.waitlisten...@148c02f[
>                            id=Facility(4)/Platform(6)/WaitlistEntry(9),
>                            userKey=User(2),
>                            entryTime=Sun Nov 01 19:16:03 PST 2009,
>                            
> platform=com.objecteffects.waitlist.db.domain.platf...@9e75f6,
>                            jdoDetachedState=<null>
>                        ],
>                        
> com.objecteffects.waitlist.db.domain.waitlisten...@154c054[
>                            id=Facility(4)/Platform(6)/WaitlistEntry(8),
>                            userKey=User(1),
>                            entryTime=Sun Nov 01 19:16:03 PST 2009,
>                            
> platform=com.objecteffects.waitlist.db.domain.platf...@9e75f6,
>                            jdoDetachedState=<null>
>                        ],
>                        
> com.objecteffects.waitlist.db.domain.waitlisten...@19ba1d8[
>                            id=Facility(4)/Platform(6)/WaitlistEntry(7),
>                            userKey=User(3),
>                            entryTime=Sun Nov 01 19:16:03 PST 2009,
>                            
> platform=com.objecteffects.waitlist.db.domain.platf...@9e75f6,
>                            jdoDetachedState=<null>
>                        ]
>                    ],
>                    jdoDetachedState=<null>
>                ],
> (rest deleted)
> 
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> 
> 2009-11-01 19:16:03.615 PST, DEBUG: [main] 
> com.objecteffects.waitlist.db.impl.dao.jdo.WaitlistEntryDaoTest.setup.95: 
> facilities entity count: 1
> 2009-11-01 19:16:03.615 PST, DEBUG: [main] 
> com.objecteffects.waitlist.db.impl.dao.jdo.WaitlistEntryDaoTest.setup.97: 
> user entity count: 3
> 2009-11-01 19:16:03.615 PST, DEBUG: [main] 
> com.objecteffects.waitlist.db.impl.dao.jdo.WaitlistEntryDaoTest.setup.99: 
> platform list size: 2
> 2009-11-01 19:16:03.615 PST, DEBUG: [main] 
> com.objecteffects.waitlist.db.impl.dao.jdo.WaitlistEntryDaoTest.setup.101: 
> platform entity count: 2
> 2009-11-01 19:16:03.615 PST, DEBUG: [main] 
> com.objecteffects.waitlist.db.domain.Platform.getWaitlistEntries.117: 
> waitlistEntries class: org.datanucleus.sco.backed.HashSet
> 2009-11-01 19:16:03.615 PST, DEBUG: [main] 
> com.objecteffects.waitlist.db.impl.dao.jdo.WaitlistEntryDaoTest.setup.103: 
> waitlistEntry list size: 6
> 2009-11-01 19:16:03.677 PST, DEBUG: [main] 
> com.objecteffects.waitlist.db.impl.dao.jdo.WaitlistEntryDaoTest.setup.105: 
> waitlistEntry entity count: 3
> 2009-11-01 19:16:03.677 PST, DEBUG: [main] 
> com.objecteffects.waitlist.db.domain.Platform.getWaitlistEntries.117: 
> waitlistEntries class: org.datanucleus.sco.backed.HashSet

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