将完整实体标记为 "updatable=false"
Mark complete entity as "updatable=false"
在一个应用程序中有多个实体类,禁止对数据库的更新语句。我想插入数据库并从中读取数据,但从不对现有记录进行任何更新。
Is there a way to mark a whole @Entity
class as updatable=false
?
可以用 @Column(updatable=false)
或类似的注释来注释每个字段,但出于显而易见的原因,我想避免这种情况。
摆脱 setter 方法也不是一个选项,因为实体 类 也用作 DTO,应用程序的其他部分需要那些 setter秒。所以这会导致对现有代码进行大量重构。
是否有另一种简单明了的方法来实现我想要的 使用 JPA 2.1 / EclipseLink (+Extensions)
你可以使用 @PreUpdate
:
@Entity
public class ReadOnlyEntity {
@PreUpdate
private void preUpdate() {
throw new UnsupportedOperationException();
}
}
这样你就永远无法更新(写入)那个实体。
在一个应用程序中有多个实体类,禁止对数据库的更新语句。我想插入数据库并从中读取数据,但从不对现有记录进行任何更新。
Is there a way to mark a whole
@Entity
class asupdatable=false
?
可以用
@Column(updatable=false)
或类似的注释来注释每个字段,但出于显而易见的原因,我想避免这种情况。摆脱 setter 方法也不是一个选项,因为实体 类 也用作 DTO,应用程序的其他部分需要那些 setter秒。所以这会导致对现有代码进行大量重构。
是否有另一种简单明了的方法来实现我想要的 使用 JPA 2.1 / EclipseLink (+Extensions)
你可以使用 @PreUpdate
:
@Entity
public class ReadOnlyEntity {
@PreUpdate
private void preUpdate() {
throw new UnsupportedOperationException();
}
}
这样你就永远无法更新(写入)那个实体。