问题描述
我有一个包含一些字段的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的字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!