1

我用hibernate写了映射到mysql表的pojo,但我不想将pojo属性绑定到mysql表字段。该代码是打击:

public class User{

    private long id;
    private String name;
    private String donotBindAttribute;
    set get......
}

如何不将属性“donotBindAttribute”绑定到 mysql 字段谁能帮助我。

4

3 回答 3

1

使这个变量瞬态。

如果您使用 JPA 注释,那么@Transient是可行的。如果您使用 hbm.xml,则根本不映射字段,它不会被视为持久属性。

于 2012-07-20T07:54:20.987 回答
1
@Transient
private String donotBindAttribute;

使其瞬态。

*假设您使用的是 JPA。

于 2012-07-20T07:55:45.593 回答
1

使用如下 -

@Transient
private String donotBindAttribute;
于 2012-07-20T07:56:35.810 回答