I have an issue regarding updating an object using JDO2 in my testcase
and I just cannot figure out what I am doing wrong. The simple usecase
I am trying is - "a user object is fetched by the DAO, the user
modifies something on the UI and hits "save" which updates the guy in
the db".

Before I tried dozer and the likes I wanted to try out the simple
scenario using a junit from the DAO's perspective. Here is the
testcase source:

                PersistenceManager pm = factory.getPersistenceManager();
                Transaction tx = pm.currentTransaction();
                tx.begin();
                User user = fetchUser(pm);
                tx.commit();
                pm.close();

                //change something
                user.setEmail("j...@samiam.com");
                user.getEmployee().setFirstName("John");

                String[] loadedFieldNames =
NucleusJDOHelper.getDetachedObjectLoadedFields(user, pm);
                String[] dirtyFieldNames =
NucleusJDOHelper.getDetachedObjectDirtyFields(user, pm);
                System.out.println("loaded ------> " + Arrays.asList
(loadedFieldNames));
                System.out.println("dirty ------> " + Arrays.asList
(dirtyFieldNames));

                pm = factory.getPersistenceManager();
                tx = pm.currentTransaction();
                tx.begin();
                pm.makePersistent(user);
                tx.commit();
                pm.close();

                pm = factory.getPersistenceManager();
                tx = pm.currentTransaction();
                tx.begin();
                user = fetchUser(pm);
                tx.commit();
                pm.close();

                assertEquals("j...@samiam.com", user.getEmail());    <--------
ASSERT FAILS

A couple of things...
1) I am detaching the "User" object that is returned from the fetchUser
() method using pm.detachCopy().
2) In the SOP I can see that the email attribute is dirty on the user
object.
3) If I use a single transaction for the entire testcase, it works.
Obviously though, I need separate transactions.
4) There are no exceptions thrown anyplace.

Can someone point out what I am doing wrong here? I might be missing
something small.

Thanks.

-stam

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

Reply via email to