stg
stg

Reputation: 2797

Mark complete entity as "updatable=false"

In one application there are several entity classes, for which update statements to the database shall be forbidden. I want to insert into and read from the database, but never do any updates on existing records.

Is there a way to mark a whole @Entity class as updatable=false?

Is there another simple and clean way to achieve what I'd like to have with JPA 2.1 / EclipseLink (+Extensions)

Upvotes: 5

Views: 1816

Answers (1)

Tobias Liefke
Tobias Liefke

Reputation: 9022

You could use @PreUpdate for that:

@Entity
public class ReadOnlyEntity {
  @PreUpdate
  private void preUpdate() {
    throw new UnsupportedOperationException();
  }
}

That way you can never update (write) that entity.

Upvotes: 7

Related Questions