views:

45

answers:

0

I have two classes, Truck and Tweeter, where every Truck must have a Tweeter and every Tweeter can have any number of Trucks associated with it. All I want is to be able to store a reference of the associated Tweeter in all my Truck objects so I can access it without having to explicitly look it up. Given a Tweeter, I don't need to know what Trucks reference it. I've read all the GAE docs (multiple times) and searched the internet for 2 days now trying to find a way to do this. It really shouldn't be this difficult, but I'm having a whole lot of trouble getting it done. I'm not understanding exactly how this relationship ought to be modeled.

Currently, pm.makePersistent is working, but an javax.jdo.JDOUserException is thrown when I try to close() the persistence manager. The exception message is Object with id "agp0cnV4bWFwcGVychkLEgdUd2VldGVyIgxrZXlkb3NhdHJ1Y2sM" is managed by a different Object Manager.

Here's the relevent pieces of the Truck class:

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
private String encodedKey;
@Persistent
@Extension(vendorName="datanucleus", key="gae.pk-name", value="true")
private String keyName;
....
@Persistent
private Tweeter tweeter;

and Tweeter:

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
private String encodedKey;
@Persistent
@Extension(vendorName="datanucleus", key="gae.pk-name", value="true")
private String keyName;
@Persistent(mappedBy = "tweeter")
private List<Truck> trucks;

I am using setKeyName(uniqueKey) in the constructors for both classes. Thanks for the help on this one!