RequestFactory - One to Many relationships set to null on server's side

135 views
Skip to first unread message

Julien Cassignol

unread,
Nov 7, 2011, 8:52:01 AM11/7/11
to Google Web Toolkit
Hi all,

I'm a true beginner with GWT and have a simple project.
My intention is to use the RequestFactory for my objects' persistence
and such, on top of vanilla DataNucleus/JDO.

I have the following model:

@PersistenceCapable(..)
A {
@PrimaryKey
Long getPK()
B getB();
void setB(B b);
void setName(String s);
String getName();

}

@PersistenceCapable(..)
B {

@PrimaryKey
Long getPK()
}

@ProxyFor(...)
AProxy extends EntityProxy {

BProxy getB();
String getName();
void setB(Bproxy b);
void setName(String s);

}

@ProxyFor(...)
BProxy extends EntityProxy {
}

I also have proper locators and interfaces such as :

public interface IARequestContext extends RequestContext {

public Request<A> storeA(AProxy a);

}

In one of my modules I do the following:

// Previously got the factory and set a private member of
the class this code is executed with a BProxy object selected from a
SuggestionBox
IARequestContext aContext = factory.getARequestContext();
AProxy a = aContext.create(AProxy.class);
Request<Void> request = aContext.storeA(a);
a = animalContext.edit(a);
b = animalContext.edit(b);
a.setName("test");
a.setB(b);
request.fire();

It goes well up to the DAO side of my application in which I have the
value of the A object's name set, but not the B object (which is
null). This fires a constraint validation error

I'm sure I'm doing something wrong and wasn't able to see a working
example of that stuff. Could someone please explain to me how it
should be done properly?

Thanks.

--
Julien Cassignol

Patrick Julien

unread,
Nov 7, 2011, 8:58:13 AM11/7/11
to google-we...@googlegroups.com

Brandon Donnelson

unread,
Nov 7, 2011, 9:22:55 AM11/7/11
to google-we...@googlegroups.com
I use JDO in my example here. I've used owned collections, but you could use one to many too. 


Brandon Donnelson

Julien Cassignol

unread,
Nov 7, 2011, 9:34:05 AM11/7/11
to google-we...@googlegroups.com
FYI the demo application isn't allowing me to add items... Which was
the feature I was curious about :-)

--
Julien Cassignol
http://www.ainulindale.net

Brandon Donnelson

unread,
Nov 7, 2011, 9:56:48 AM11/7/11
to google-we...@googlegroups.com
Hmmmm.... Seems that I have some bugs hiding in the code :). I just tried and its working for me, although I found a couple of delete erros on the server. For the most part, it should work. :)

I'm curious if you refresh it and try again, if it would work? I think I have a UI error. I'll chase it down.

Thanks,
Brandon

Julien Cassignol

unread,
Nov 7, 2011, 10:13:08 AM11/7/11
to google-we...@googlegroups.com
Nope, still won't work here.

I have a look at the source though and it seems to me that you're
doing about the same thing I do, that is for my example:

Create a context
Create a AProxy
Context-Edit BProxies settable on A
Set BProxies on A
Persist.

This goes well for me up to the point of the construction of the
Domain object. As I was saying, my A object has all the attributes
supposed to be there BUT for the other entity proxies (in my case A
has a name but no B).
I didn't manage to find out where this was set in the labyrinthic
sources, and I'm wondering if this could not be due to a
misunderstanding on my side of the proper annotations I should set on
my domain objects.

In this specific case all objects are EntityProxy (no ValueProxy) and
all have proper primary keys.
B objects are currently properly retrieved from the database and
populate a SuggestBox. When I try to use
((MySuggestions<BProxy>)event.getSelectedItem()).getEntity() (using a
custmo SuggestionSelection which keeps the entityproxy) I can get the
proper entity and I can set it to my AProxy object.

The problem resides between the fire() call (which according to
inspect contains the proper values of the AProxy) and the actual DAO
call in which I have my A object with all the values but for the
values of the proxified B objects.

I'm not sure I'm clear enough :-)

Brandon Donnelson

unread,
Nov 7, 2011, 10:45:20 AM11/7/11
to google-we...@googlegroups.com
hmmm. I think I used Proxy A for B DTO, in this demo, if I understand you right. Or in other words I suppose I'm using the parent's proxy.


Not sure that will help.
Brandon Donnelson

Julien Cassignol

unread,
Nov 7, 2011, 12:11:56 PM11/7/11
to google-we...@googlegroups.com
Problem solved in the end thanks to someone on IRC!

I forgot that during the whole setup I kept using TODOs methods in my
DAO. Namely, one used by the Locator to retrieve objects with the
find() method.
As the DAO methods kept returning null, the mapping kept setting a
null value to my domain object. Implementing the method solved the
problem and the mapping went as supposed.

PEBKAC in the end :-)

Reply all
Reply to author
Forward
0 new messages