我用hibernate写了映射到mysql表的pojo,但我不想将pojo属性绑定到mysql表字段。该代码是打击:
public class User{
private long id;
private String name;
private String donotBindAttribute;
set get......
}
如何不将属性“donotBindAttribute”绑定到 mysql 字段谁能帮助我。
使这个变量瞬态。
如果您使用 JPA 注释,那么@Transient是可行的。如果您使用 hbm.xml,则根本不映射字段,它不会被视为持久属性。
@Transient
private String donotBindAttribute;
使其瞬态。
*假设您使用的是 JPA。
使用如下 -
@Transient
private String donotBindAttribute;