# @Immutable

> Reference: [@Immutable in Hibernate](https://www.baeldung.com/hibernate-immutable)

### What is @Immutable?

* When this annotation is added to an `Entity`, updates will not work
* When added to a `Collection`, add & delete will not work

### Behavioral Changes When @Immutable Annotation is Added

* INSERT
  * No changes
* UPDATE
  * Hibernate does not throw an exception and simply `ignores` the UPDATE operation execution
  * Separate configuration is needed to trigger an exception
* DELETE
  * No changes

### Things to Note

* `@Immutable` entities can still be updated via JPQL or Criteria
* However, starting from **5.2.17**, updates have been blocked but only a WARNING is logged
  * To also trigger an error, set the following property

    ```java
    hibernate.query.immutable_entity_update_query_handling_mode=exception
    ```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://chloe-codes1.gitbook.io/til/spring/jpa-annotations/03_immutable.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
