51

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.

Adnan
  • 25,882
  • 18
  • 81
  • 110

3 Answers3

82

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

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

or:

@Transient
private String status;
Kel
  • 7,680
  • 3
  • 29
  • 39
13

Mark it as @Transient, and it won't be part of the DB schema.

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
11

If you annotate a field with @Transient it will not be persisted.

jjungnickel
  • 1,264
  • 11
  • 9