Hibernate Annotations - How do I exclude a bean´s field from mapping?

独自空忆成欢 提交于 2020-01-01 04:07:32

问题


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?

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

Thanks in advance.

Code right bellow:

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

回答1:


Use the @Transient annotation.


/* snip... */

@Transient
private Boolean errorStatus;

@Transient
private String operationResultMessage;

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



来源:https://stackoverflow.com/questions/5386487/hibernate-annotations-how-do-i-exclude-a-bean%c2%b4s-field-from-mapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!