Hibernate Annotations - 如何从映射中排除 bean 的字段? [英] Hibernate Annotations - How do I exclude a bean´s field from mapping?
问题描述
我有一个包含一些字段的 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
提前致谢.
右侧代码:
** 省略了 Getter 和 Setter!
** 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
注释.
Use the @Transient
annotation.
/* snip... */
@Transient
private Boolean errorStatus;
@Transient
private String operationResultMessage;
显然,如果您要注释的是 getter/setter 而不是字段,那么 @Transient
注释就在那里.
Obviously, if you're annotating the getters/setters rather than the fields, that's where the @Transient
annotation would go.
这篇关于Hibernate Annotations - 如何从映射中排除 bean 的字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!