Uploaded image for project: 'Hibernate ORM'
  1. HHH-12387

Immutable entities can be updated via bulk update queries

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects versions: None
    • Fix versions: 5.2.17, 5.3.0.CR2
    • Components: hibernate-core
    • Labels:
      None
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      Description

      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.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: