| Assuming we have an @Immutable entity:
@Entity(name = "Event")
@Immutable
public static class Event {
@Id
private Long id;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "created_on")
private Date createdOn = new Date();
@Column(name = "event_key")
private String eventKey;
@Column(name = "event_value")
private String eventValue;
public Event(Long id, String eventKey, String eventValue) {
this.id = id;
this.eventKey = eventKey;
this.eventValue = eventValue;
}
private Event() {
}
public Long getId() {
return id;
}
public Date getCreatedOn() {
return createdOn;
}
public String getEventKey() {
return eventKey;
}
public String getEventValue() {
return eventValue;
}
}
All entity changes are prevented, but bulk update is still possible:
entityManager.createQuery(
"update Event " +
"set eventValue = :eventValue " +
"where id = :id")
.setParameter("eventValue", "10")
.setParameter("id", 1L)
.executeUpdate();
We should probably prevent these bulk update queries as well either by throwing an exception or logging a WARNING message and returning an empty result set. |