AppEngine - Multiple Relations of Same Type

Viewed 375

I need to have two objects of the same type. By default appengine doesn't allow it, but I found this parameter: datanucleus.appengine.allowMultipleRelationsOfSameType, so I can save the two same type objects.

In debug mode, before calling the makePersistent method I checked a value inside each object and they were differents, however, when I tried to recover the values from the datastore, they were the same. Both had the value of the second object?

This code is to save the object FaseGAE:

manager = GAEDAOFactory.get().getPersistenceManager();
Key faseKey = KeyFactory.stringToKey(grupo.getFaseKey());
FaseGAE faseGAE = manager.getObjectById(FaseGAE.class, faseKey);
faseGAE.addGrupoGAE(grupoGAE);
faseGAE = manager.makePersistent(faseGAE);
manager.close();

This code is to get the object:

manager = GAEDAOFactory.get().getPersistenceManager();
FaseGAE faseGAE2 = manager.getObjectById(FaseGAE.class, faseKey);

FaseGAE object:

@PersistenceCapable
public class FaseGAE {

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent private List<GrupoGAE> grupos;

GrupoGAE object:

@PersistenceCapable
public class GrupoGAE {

    @PrimaryKey
    @Persistent (valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent private List<MyClass1> list;

MyClass1 object:

@PersistenceCapable
public class MyClass1 {

    @PrimaryKey
    @Persistent (valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent private MyClass2 sameTypeObject1;
    @Persistent private MyClass2 sameTypeObject2;
    @Persistent private String testValue1;
    @Persistent private String testValue2;

MyClass2 Object:

@PersistenceCapable
public class MyClass2{

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

testValue1 and testValue2 keeps different values, but sameTypeObject1 and sameTypeObject2 have the value of sameTypeObject2. I checked the datastore and both objects were created with different values. It seems like both point to the same reference.

Am I doing something wrong?
Something it's missing to work with same type relations?
Definitely AppEngine doesn't allow same type relations?

1 Answers
Related