Updating objects

Figure 850. Adding a setter Slide presentation Create comment in forum
@Entity
public class StudyCourse {
  @Id @Column(length = 3) private String shortName;

  @Column(length = 150, nullable = false, unique = true)
  private String fullName;

  public void setFullName(final String fullName) {
    this.fullName = fullName;
  }
 ...
}

Figure 851. Update language Slide presentation Create comment in forum
final StudyCourse csm = entityManager.
  find(StudyCourse.class, "CSM");

final EntityTransaction tx =
  entityManager.getTransaction();

tx.begin();
  csm.setFullName( 
   "Computerwissenschaft und Medien");
tx.commit(); 
MariaDB [hdm]>
        select * from StudyCourse;
+---------+---------------------+
|shortName| fullName            |
+---------+---------------------+
| CSM     | Computerwissenschaft|
|         | und Medien          |
+---------+---------------------+

Retrieving instance from database. Variable csm is bound to the persistence context.

Changing instance's fullName property's value.

Committing transaction will automatically commit all persistence context related changes.