hibernate 列数据转换

在需要转换的model字段上添加注释

@ColumnTransformer(read="kg*1000",write="?/1000")

表结构:
hibernate 列数据转换_第1张图片
model:

@Entity
@Table(name = "testguid")
public class GUID implements Serializable {

	@Id
	@Column(name = "guid")
	@GeneratedValue(generator="test")
	@GenericGenerator(name="test",strategy="uuid.hex")
	private String guid;
	@Column(name = "name")
	private String name;

	
	@ColumnTransformer(read="kg*1000",write="?/1000")
	
	private  long kg;
	
	
	public long getkg() {
		return this.kg;
	}

	public void setkg(long guid) {
		this.kg = guid;
	}
	
	public String getguid() {
		return this.guid;
	}

	public String getname() {
		return this.name;
	}

	public void setguid(String guid) {
		this.guid = guid;
	}

	public void setname(String name) {
		this.name = name;
	}
}

你可能感兴趣的:(java)