Multiple Relations of Same Type

7 views
Skip to first unread message

David Gonzalez

unread,
Jun 14, 2011, 3:45:48 PM6/14/11
to Google App Engine
Hi,

I have 3 classes: MyClass, MySubClass and ProblemClass
The first one have two MySubClass objects: MySubClass1 and MySubClass2
Each MySubClass has a ProblemClass object: ProblemClass1 and
ProblemClass2

Just before call 'manager.makePersistent(MyClass);' I checked the
attribute in both ProblemClass objects and they were differents (That
´s OK).
But when I tried to recover MyClass object from the datatore the
attributes inside the ProblemClass objects are equal (THAT'S WRONG).
Both ProblemClass have the values of ProblemClass2

Checking the datastore I saw both ProblemClass objects were created
(With correct values), however MySubClass1 and MySubClass2 seems to be
pointing to the same ProblemClass

All classes have the same key type:

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

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

PLS HELP!!!!! I'm really stuck!!!

Robert Kluin

unread,
Jun 17, 2011, 5:05:37 AM6/17/11
to google-a...@googlegroups.com
Hi,
You might want to include some of the relevant code, such as your
model definitions and the code that sets and persists the entities.
Also note that there is a Java specific group; might have a better
chance of a Java whiz spotting it and helping you out there.


Robert

> --
> You received this message because you are subscribed to the Google Groups "Google App Engine" group.
> To post to this group, send email to google-a...@googlegroups.com.
> To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
>
>

David Gonzalez

unread,
Jun 23, 2011, 9:47:01 PM6/23/11
to Google App Engine
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?

PLS HELP!!!!!


Reply all
Reply to author
Forward
0 new messages