在实体类增加下面注解
@SelectBeforeUpdate(value=true)
@DynamicUpdate(value=true)
示例如下
package com.test.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;
@Entity
@Table(name = "User", schema = "dbo", catalog = "test")
@SelectBeforeUpdate(value=true)
@DynamicUpdate(value=true)
public class User implements java.io.Serializable {
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
private Integer id;
@Column(name = "userName", length = 50)
private String userName;
}