将完整实体标记为 "updatable=false"

Mark complete entity as "updatable=false"

在一个应用程序中有多个实体类,禁止对数据库的更新语句。我想插入数据库并从中读取数据,但从不对现有记录进行任何更新。

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

是否有另一种简单明了的方法来实现我想要的 使用 JPA 2.1 / EclipseLink (+Extensions)

你可以使用 @PreUpdate

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

这样你就永远无法更新(写入)那个实体。