【问题标题】:Hibernate Annotations - How do I exclude a bean´s field from mapping?Hibernate Annotations - 如何从映射中排除 bean 的字段?
【发布时间】:2011-07-20 04:18:12
【问题描述】:

我有一个包含一些字段的 bean,其中两个不打算由 hibernate 映射(errorStatus 和 operationResultMessage)。我如何告诉 Hibernate(通过注释)我不想映射这些字段?

*bean中的映射表没有字段:errorStatus和operationResultMessage

提前致谢。

代码如下:

** 省略了 Gettter 和 Setter!

@Entity
@Table(name = "users")
public class AccountBean implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;

@Column(name = "name")
private String userName;

@Column(name = "email")
private String email;

@Column(name = "login")
private String login;

@Column(name = "password")
private String password;

private Boolean errorStatus;

private String operationResultMessage;

【问题讨论】:

    标签: hibernate annotations


    【解决方案1】:

    使用@Transient 注释。


    /* snip... */
    
    @Transient
    private Boolean errorStatus;
    
    @Transient
    private String operationResultMessage;
    

    显然,如果您要注释 getter/setter 而不是字段,那么@Transient 注释会去。

    【讨论】:

    • 感谢您的提示,马特,它非常有用!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-27
    • 1970-01-01
    • 1970-01-01
    • 2011-02-03
    • 2011-03-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多