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<Advert> adverts;
        public List<Advert> getAdverts() {return this.adverts;}
        public void setAdverts(List<Advert> 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<Property> findAllProperties() {
                  PersistenceManager pm = persistenceManager();
            try {
              List<Property> list = (List<Property>) 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<List<PropertyProxy>>(){

                                        @Override
                                        public void 
onSuccess(List<PropertyProxy> response) {

                                                String str = "Properties: ";
                                                for (PropertyProxy property : 
response){
                                                        str += property.getId() 
+ " " + property.getDescription();
                                                }
                                                Window.alert(str);
                                        }
                                });
                        }
                });


On Mar 4, 7:58 am, savilak <[email protected]> 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 Appengine and GWT adoption from the
> developer community.
>
> The DynatableRF sample app that Google suggests covers only a small
> subset of relationships
> and has a lot of irrelevant code plus we do not believe that this is
> the proper way to do it (copying and storing objects all the
> time ...). At least for the unidirectional we managed to do it in a
> much simpler and straightforward way.
>
> Any help would be much appreciated from us and we believe from a lot
> of others.
>
> Thank you for your time.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to