休眠注释-如何从映射中排除bean的字段? [英] Hibernate Annotations - How do I exclude a bean´s field from mapping?

查看:82
本文介绍了休眠注释-如何从映射中排除bean的字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I´ve got a bean containing some fields, and two of them are not intended to be mapped by hibernate (errorStatus and operationResultMessage). How do I tell Hibernate (via annotations) that I don´t want to map those fields?

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

*The mapped table in the beans does not have the fields: errorStatus and operationResultMessage

谢谢.

代码右下方:

**忽略了Gettters和Setters!

** Gettters and Setters ommited!

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

推荐答案

使用 @Transient 注释.

/* snip... */

@Transient
private Boolean errorStatus;

@Transient
private String operationResultMessage;

很明显,如果要标注的是getters/setter而不是字段,那么@Transient注释就是在这里.

Obviously, if you're annotating the getters/setters rather than the fields, that's where the @Transient annotation would go.

这篇关于休眠注释-如何从映射中排除bean的字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆