开发者

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

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.


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

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

or:

@Transient
private String status;


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜