Updating data using an access bean

You can update data in your business logic by using an access bean to retrieve and change data, even if the underlying access method is JPA.

About this task

When you update data in your business logic, you will first be Finding data using an access bean, and then using the setters on the class to change data. You do not need to explicitly use EntityManager to make the changed JPA entity persistent. Once the transaction commit or flush operation is called, the changed data will be committed to the database.

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");