Qual è il modo standard per implementare un aggiornamento semplice?Come implementare il metodo update() in DAO usando EntityManager (JPA)?
Esempio: abbiamo Utente con numero di telefono NNNNNNN e ora vogliamo impostarlo su YYYYYY.
@PersistenceContext
private EntityManager em;
public void update (User transientUser) {
what should be here?
}
entità Utente più semplice possibile:
@Entity
@Table (name = "USER")
public class User {
@Id
@GeneratedValue
private Integer id;
@Column (nullable = false, unique = true)
private String login;
private String phone;
public User() { }
... //some setters and getters
}
em.merge (transientUser)? – marcosbeirigo
forse, non sono sicuro che sia lo – Roman
, questo è quello che ho adesso. Ma non l'ho ancora testato a causa del fatto che non è così facile configurare il contesto delle unit test. – Roman