How to save just a child?

17 views
Skip to first unread message

MagusDrk

unread,
Dec 12, 2011, 6:52:44 PM12/12/11
to Google Web Toolkit
Hi all!

I'm trying to update some child objects to the datastore via
PersistenceManager, but my data is never updated/overrided when I use
makePersistent with such object directly. I need to do that in order
to avoid sending a whole entity via RPC, but to send just the child
object I need to update.

1. When I do something like saveMethod(parent), then the parent object
and the child are saved both.

2. Then, when I load the child and I try so save it again like:
saveMethod(child) the method "saves" it correctly (no errors found
and returns true)

3. But when I try to reload the child, It has not being updated.

(See context above)

Aditionally, I want to delete some of these children, but It has been
imposible too, like this:

parent.removeChild(childIndex);//this removes the child from ArrayList
of children
saveMethod(parent);

But, when I reload parent, it stil has the "removed" child.

(Help me please!). Thanks a lot.

Magus.

==========================================================
Some context:

Classes:

@PersistenceCapable(identityType = IdentityType.APPLICATION,
detachable = "true")
public class Parent{

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;

@Persistent(defaultFetchGroup = "true")
private List<Child> children;
...
}

@PersistenceCapable(identityType = IdentityType.APPLICATION,
detachable = "true")
public class Child{

@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@PrimaryKey
private Key id;

@Persistent
private String field;
...

}

saveMethod:


public <T> boolean saveMethod(final T object) {

PersistenceManager pm =
PersistenceManagerFactory.get().getPersistenceManager();

try {
pm.makePersistent(object);
return true;
} catch (Exception e) {
return false;
} finally {
pm.close();
}
}

MagusDrk

unread,
Dec 15, 2011, 5:28:22 PM12/15/11
to Google Web Toolkit
Hi, an aditional data, I'm doing it in a JUnit test clase. I don't
know if it can influence in the problem. I'm Still waiting for a
response.

Ed

unread,
Dec 17, 2011, 8:45:35 AM12/17/11
to google-we...@googlegroups.com
I think this has nothing to do with GWT and it depends of your Persist layer (JPO) that you use. Maybe Hibernate... I donno...
Try to unit test it witout the front end (Not in GWTTestCase)...
- Ed 

MagusDrk

unread,
Dec 19, 2011, 8:11:05 AM12/19/11
to Google Web Toolkit
Thanks, Ed, I'm not using GWTTestCase in this part (Actually, I'm
trying to use GWTTestCase with no success but in another forum) I'm
just using a JUnit class. I don't know if I'm missing something in
the persistence manager, I just found a getDetachCopy (or something
like that) on friday, but I just going to check it today. Thanks!
Reply all
Reply to author
Forward
0 new messages