The bidirectional owned one to may relationship in requestFactory
worked
with one bypass!
The issue for was the following. The data were saved properly but
when we were fetching the child objects were null.
This is due to the lazy loading of data from appengine.
When you read an object which is related to another then the child
object is retrieved with null
values although it actually has values. In order to force population
of the child object you have
to use the @Persistent (defaultFetchGroup = "true") annotation (JDO)
AND call the find method
using the with() method call (see
http://code.google.com/webtoolkit/doc/latest/DevGuideRequestFactory.html)
If you do only one of these then it will not work!
The .with() is not working for us when we try to retrieve the parent
from the child.
We made two different find methods for the child objects one that is
doing lazy loading and
one that is not doing lazy loading. We achieved the non lazy behaviour
just by reading the parent object at server side.
In case someone can give us a better way to do this we will be much
obliged.
E.g. Property Entity -- Advert Entity (1 Property has N Adverts)
You will find the fully functional code here:
https://bitbucket.org/repo/all?name=DemoRequestFactoryJDO
Keep in mind that this is just a draft project
(at some parts it has hard coded key values please replace them with
appropriate ones).
Parts of code that interest you.
In the Property Class use the annotation
...
@Persistent (mappedBy = "property", defaultFetchGroup = "true")
@Element (dependent = "true")
private List adverts;
public List getAdverts() {return this.adverts;}
public void setAdverts(List adverts) {
this.adverts=adverts;
}
...
public static Property findProperty(String encodedKey) {
if (encodedKey == null) {
return null;
}
PersistenceManager pm = persistenceManager();
try {
Property x = pm.getObjectById(Property.class,
encodedKey);
return x;
}
finally {
pm.close();
}
}
//List of properties
@SuppressWarnings("unchecked")
public static List findAllProperties() {
PersistenceManager pm = persistenceManager();
try {
List list = (List) pm.newQuery("select from
" + Property.class.getName()).execute();
// force to get all the properties
list.size();
return list;
} finally {
pm.close();
}
}
In the Advert Class use the annotation
@Persistent (defaultFetchGroup = "true")
private Property property;
public Property getProperty() {return this.property;}
public void setProperty(Property property){this.property=property;};
Client Side Code
//Get All Properties Handler
btn.addClickHandler(new ClickHandler(){
@Override
public void onClick(ClickEvent event) {
// TODO Auto-generated method stub
final PropertyRequest request1 =
requestFactory.propertyRequest();
request1.findAllProperties().with("adverts").fire(new
Receiver>(){
@Override
public void
onSuccess(List response) {
String str = "Properties: ";
for (PropertyProxy property :
response){
str += property.getId()
+ " " + property.getDescription();
}
Window.alert(str);
}
});
}
});
On Mar 4, 7:58 am, savilak wrote:
> We were using RPC to persist our data and we want to shift to
> RequestFactory!!!
>
> We managed to make One to One and One to Many Unidirectional managed
> relationships work with JDO.
>
> We try for 2 weeks and the bidirectional is not working!!!
> We persist then we use AppWrench and we see that the data are saved
> but when we retrieve
> with our code (getObjectById ...) the related child objects return
> null.
>
> Can someboby please provide a small functional SAMPLE of JDO 1:M
> bidirectional relationship.
>
> Unfortunately Google is not providing working samples for major areas
> that is releasing in GWT or AppEngine!!!
> I pretty sure that this is killing Appe