I read GAE doc about JDO but i didn't find such example that fit to my scenario. Please help me.
I have two JDO classes like A
and B
. "A"
class have one to many relationship with "B"
. This relation is unowed also not dependent. class "A"
and "B"
has following structure (to make it simple i am not using annotations)
class A {
private String name;
private String id; // primary Key
private List<B> b;
..... getter setter
}
class B {
private Key key; // primary Key
private String id; // this is the attribute of the Class A
private String someData;
}
Now my scenario is that First I created class "A"
objects one by one and save it to the data store using Persistent manager. For this storing "List<B> b
" will be null bcz i don't have data for it.
After that lets suppose I provide a form that have two fields one for the "id"
attribute of the Class "A"
and other for "someData
" attibute. In this user provide the "id"
of one of the stored objects of class "A"
. When User submit the result i have to create a class "B"
object and save it to data store and also have to add it in list of B
of its corresponding Class "A"
object. I hope you understand what i want to do.
Now my question is that what approach i have to use for maintaining this one to many relationship of JDO classes. Either i have to first retrieve the class "A"
object based on the "id"
provided in the form and after getting the object i get "list of B"
class objects and add a "B"
class object in the list and then save the class "A"
object( As object is attached to the PM its automatically save) or other approach is that I just create the class "B"
object and save it to the data store using PM.
If just creating B
class object and saving it to the data store is persistent to the relationship. I simple word when i get the class A
objects does "list of B"
class object have the all objects linked to class "A" object ( because B class has attribute which is the primary key of class A
)
Thanks