JDO - object update

I am experimenting with the Google App Engine and keep the JDO option. I would like to know if it is possible to map a transition object to a persist object? Or something to update a permanent object using a transition object?

In the coding examples, I see the following code fragment for updating objects:

public void updateEmployeeTitle(User user, String newTitle) { PersistenceManager pm = PMF.get().getPersistenceManager(); try { Employee e = pm.getObjectById(Employee.class, user.getEmail()); if (titleChangeIsAuthorized(e, newTitle) { e.setTitle(newTitle); } else { throw new UnauthorizedTitleChangeException(e, newTitle); } } finally { pm.close(); } } 

But this is not what I want, does anyone know if I can update the whole object, for example JPA: object.update ();

So, I would like something like this:

 public User update(User u) { PersistenceManager pm = PMF.get().getPersistenceManager(); User usr; try { usr = pm.getObjectById(User.class, u.getId()); // copy transient object u to persist object usr. // on update of usr all changes in object u are persistent. } finally { pm.close(); } return u; } 
+6
java google-app-engine jdo
source share
1 answer

The transition object does not have an β€œidentity,” so there is no way to find it in the data warehouse. Think carefully if you want to use transitional objects, or it would be better to just use separate objects. JPA uses the equivalent of a "separate" object. JDO can do this too, and then you simply type pm.makePersistent (detachedObj);

- Andy ( DataNucleus )

+2
source share

All Articles