One-to-many relation problem

5 views
Skip to first unread message

Bat

unread,
Mar 28, 2012, 4:41:11 AM3/28/12
to google-a...@googlegroups.com

Hi All,


I'm trying to use the one-to-many relation with heritance but without

success. Let me explain.


I have 3 classes :


@PersistenceCapable

@Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)

   public abstract class Op {

   @PrimaryKey

   @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)

   public Key key;


   @Persistent(mappedBy = "op")

   @Element(dependent = "true")

   private ArrayList<Entry> entryArr = new ArrayList<Entry>();

}


@PersistenceCapable

public class ExtendedOp extends Op {

   public double quota;

}


@PersistenceCapable

public class Entry {

@PrimaryKey

@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)

public Key key;


@Persistent

   private Op op = null;

}


When I persist, I use this code :

ExtendedOp op = new ExtendedOp();

op.addNewEntry(new Entry());

op.addNewEntry(new Entry());

pm.makePersistent(op);


After, I persisted, I reload the "ExtendedOp" with this :

String connectionQuery = "select from " + ExtendedOp.class.getName();

opArr = (List<ExtendedOp>) pm.newQuery(connectionQuery).execute();

    if (opArr != null) {

               for (ExtendedOp opExt : opArr) {

                   if ( opExt.getEntryArr() != null)

                       for (Entry entry : sale.getEntryArr()) {

                           System.out.println("ok"); //works!

                           if (entry.getOp() != null)

                               System.out.println("perfect"); //never

display

                       }

               }

           }


The problem is : the Entry has the field "operation" always null. This

field is from the relation one-to-many. Maybe this field is still null

because is class type is "parent" of ExtendedOp?


Could you help me to solve that problem?


Thanks you very much,


Bat

Bat

unread,
Mar 27, 2012, 12:10:57 PM3/27/12
to Google App Engine
Reply all
Reply to author
Forward
0 new messages