twinster
twinster

Reputation: 86

Spring Boot Entity DynamicUpdate

I am writing API on Spring Boot have an issue with partial update of entity. When I want to update for example just name of user, spring sees other fields as null and replaces data with nulls in Database. As i read in documentation @DynamicUpdate must fix this issue but it is not working for me.

Here is my user Entity.

@Entity
@Table(name="users")
@DynamicUpdate
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    //other fields...

}

Upvotes: 0

Views: 377

Answers (1)

Yogesh Katkar
Yogesh Katkar

Reputation: 132

Use merge instead

Entity en = sessionFactory.getCurrentSession().get(id);
en.setName("abc");
sessionFactory.getCurrentSession().merge(en);

Performance issue with Entity( dynamicUpdate = true )
In a large table with many columns (legacy design) or contains large data volumes, update some unmodified columns are absolutely unnecessary and great impact on the system performance.

Upvotes: 1

Related Questions