Hibernate: Add a property in my class that is not mapped to a db-table

Adnan picture Adnan · Oct 24, 2010 · Viewed 31.9k times · Source

I have a table tbl_sky that has 2 properties name and model and I would use Hibernate annotation like;

@Entity
@Table(name="tbl_sky")
public class Sky implements Serializable {
    private String name;
    private String model;
    private String status;

    @Id
    public String getName() {
        return name;
    }
.
.
.

But I need to add one more property status that does not exist in the table but is needed in the class. How could I declare that property so that I have it in my class but not in my db-table?

All help is appreciated.

Answer

Kel picture Kel · Oct 24, 2010

Use @Transient annotation for field you are not going to store in DB:

@Transient
public String getStatus() {
    return status;
}

or:

@Transient
private String status;