Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3615450
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:22:30+00:00 2026-05-18T22:22:30+00:00

I am trying to learn JDO (and at the same time its GAE and

  • 0

I am trying to learn JDO (and at the same time its GAE and Spring intricacies) by creating a small web app, and am having trouble getting updated domain objects to persist back to the database. I initially grab the entity from the DB and detach it so that I can show it to the user and allow them to change it. Once the user has made the changes and posts the form back to the app, I again grab the entity from the DB (detached), update its properties, and then call a pm.makePersistent(). The abbreviated code is as follows:

User Domain Object:

@PersistenceCapable(detachable="true")
public class User extends BaseEntity {
    @Persistent
    private String firstName = "";
    @Persistent
    private String middleInitial = "";
    @Persistent
    private String lastName = "";
}

DAO Read Method:

public User read(Key key) throws DataException {
    PersistenceManager pm = PMF.get().getPersistenceManager();
    User pkg, detached = null;
    try {
        pkg = (User) pm.getObjectById(User.class, key);
        detached = pm.detachCopy(pkg);
        detached.setIsAlreadyInDB(true);
    }
    catch (Exception e) {           
        throw new DataException("An error occured trying to read the User object. Details:\n" + e.getMessage());
    }
    finally {
        pm.close();
    }
    return detached;
}

DAO Update Method:

private void update(User pkg) throws DataException {
    PersistenceManager pm = PMF.get().getPersistenceManager();
    Transaction tx = pm.currentTransaction();

    try { 
        tx.begin();         
        pm.makePersistent(pkg);
        tx.commit();
    }
    finally { 
        if (tx.isActive()) tx.rollback();
        pm.close();
    }
}

Now when I get down into the update method, I’ve proven to myself that I’m working with just the same object from my read via inspecting its hashCode(), I’ve changed a value using the domain object’s setter method, I’ve even printed the changed value to the console to make sure it’s getting done, and JDOHelper.isDirty() still returns false, and therefore none of the changes get persisted back to the database.
Any thoughts on what I’m missing or if I’m approaching this from the wrong angle? Thank you for helping out a JDO beginner!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T22:22:30+00:00Added an answer on May 18, 2026 at 10:22 pm

    JDOHelper.isDirty is for managed objects. A detached object is not managed. DataNucleus provides a helper method of its own to get the dirty fields while detached since the logic is implementation-specific
    String[] dirtyFieldNames = NucleusJDOHelper.getDetachedObjectDirtyFields(obj, pm);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.