Beig
Beig

Reputation: 405

Set field to not update to database

Is it possible to set a field so that it get not saved/stored in DB?

@Entity
@Table(name = "users")
public class User implements Serializable {
    @Column(name = "quota")
    private int quota;
...
}

If the value is changed it should not be saved/stored in the database. But I dont want to make it @Transient cause the value is stored in the db.

Is this possible with an Annotation? Or do I have to check the value before saving?

Thanks

Upvotes: 1

Views: 410

Answers (1)

Dragan Bozanovic
Dragan Bozanovic

Reputation: 23552

Yes, use updatable:

@Column(name = "quota", updatable = false)
private int quota;

Javadoc:

(Optional) Whether the column is included in SQL UPDATE statements generated by the persistence provider.

Upvotes: 1

Related Questions