---
title: "Session: How to Get and Modify Entity Metadata"
url: "https://docs.ravendb.net/6.2/client-api/session/how-to/get-and-modify-entity-metadata"
version: "6.2"
language: "java"
---

# Session: How to Get and Modify Entity Metadata

> Client language: Java. Also available for [C#](https://docs.ravendb.net/6.2/client-api/session/how-to/get-and-modify-entity-metadata.md), [Node.js](https://docs.ravendb.net/6.2/client-api/session/how-to/get-and-modify-entity-metadata.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

When a document is downloaded from the server, it contains various metadata information like ID or current change-vector. This information is stored in a session and is available for each entity using the `getMetadataFor` method from the `advanced` session operations.

## Get the Metadata

```java
<T> IMetadataDictionary getMetadataFor(T instance);
```

| Parameters | | |
| - | - | - |
| **instance** | T | Instance of an entity for which metadata will be returned. |

| Return Value | |
| - | - |
| IMetadataDictionary | Returns the metadata for the specified entity. Throws an exception if the `instance` is not tracked by the session. |

### Example

```java
Employee employee = session.load(Employee.class, "employees/1-A");
IMetadataDictionary metadata = session.advanced().getMetadataFor(employee);
```

## Modify the Metadata

After getting the metadata from `session.advanced().getMetadataFor` you can modify it just like any other map.

> **Note**
>
> Keys in the metadata that starting with @ are reserved for RavenDB use

### Example I

```java
User user = new User();
user.setName("Idan");

session.store(user);

IMetadataDictionary metadata = session.advanced().getMetadataFor(user);
metadata.put("Permissions", "READ_ONLY");
session.saveChanges();
```

### Example II

```java
User user = session.load(User.class, "users/1-A");
IMetadataDictionary metadata = session.advanced().getMetadataFor(user);
metadata.put("Permissions", "READ_AND_WRITE");
session.saveChanges();
```

## See also

- [What is a Session and How Does it Work](https://docs.ravendb.net/6.2/client-api/session/what-is-a-session-and-how-does-it-work.java.md)
- [How to Get Entity Change-Vector](https://docs.ravendb.net/6.2/client-api/session/how-to/get-entity-change-vector.java.md)
- [How to Get Entity Last Modified](https://docs.ravendb.net/6.2/client-api/session/how-to/get-entity-last-modified.java.md)
- [Indexing Metadata](https://docs.ravendb.net/6.2/indexes/indexing-metadata.java.md)
