Develop > Persistence layer


Update data using an access bean

You can update data in the business logic by using an access bean to retrieve and change data. The commitCopyHelper() method is used to commit the changes you make in the access bean to the WebSphere Commerce database.

When you update data in the business logic, we will first be Find data using an access bean, and then using the setters on the class to change data. At this point, the data is cached locally in the access bean. If you update values in the local cache of the access bean, also include a commitCopyHelper() call to update the database with the updated information. If you do not use the commitCopyHelper() method, any changes you make using setters on the access bean will not be persisted.

The following example shows how to retrieve, update, and commit data on the UserProfileAccessBean:


Procedure

  1. Create a new access bean:

    UserProfileAccessBean abUserProfile = new UserProfileAccessBean();
    

  2. Set the primary key:

    abUserProfile.setInitKey_UserId(getUserId().toString());
    

  3. Update the display name:

    abUserProfile.setDisplayName("My display name");
    

  4. Update the description for the user:

    abUserProfile.setDescription("My user description");
    

  5. Commit the changes:

    abUserProfile.commitCopyHelper();