Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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;
like image 595
Guilherme Calegari Avatar asked Mar 22 '11 03:03

Guilherme Calegari


People also ask

How do you ignore a field in an entity?

So, when the entity identifier and an association share the same column, you can use @MapsId to ignore the entity identifier attribute and use the association instead.

Which of the following annotation is used for is a mapping?

The @Basic annotation is used to map a basic attribute type to a database column.

What will happen if @table is not specified while defining pojo?

If no @Table is defined the default values are used: the unqualified class name of the entity. For example if you have: @Entity public class MyTest{ ... Your table will have the name my_test in your database.

Which annotation is used for mapping is a relationship in hibernate?

In hibernate we can map a model object into a relation/table with the help of @Entity annotation.


1 Answers

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.

like image 74
Matt Ball Avatar answered Oct 17 '22 18:10

Matt Ball