您的位置:首页 > 其它

Hibernate update方法,只更新指定字段

2017-04-28 10:19 375 查看
在实体类增加下面注解

@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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: