---
title: "Global Identifier Generation Conventions"
url: "https://docs.ravendb.net/6.2/client-api/configuration/identifier-generation/global"
version: "6.2"
language: "java"
---

# Global Identifier Generation Conventions

> Client language: Java. Also available for [C#](https://docs.ravendb.net/6.2/client-api/configuration/identifier-generation/global.md), [Node.js](https://docs.ravendb.net/6.2/client-api/configuration/identifier-generation/global.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."

\#Global Identifier Generation Conventions

Documents that have the same `@collection` metadata belong to the same [collection](https://docs.ravendb.net/6.2/client-api/faq/what-is-a-collection.md) on the server side. Collection names are also used to build document identifiers.

```java
conventions.setFindCollectionName(
  clazz -> // function that provides the collection name based on the entity class
```

## TransformClassCollectionNameToDocumentIdPrefix

Collection names determined by recently described convention functions aren't directly used as prefixes in document identifiers. There is a convention function called `TransformClassCollectionNameToDocumentIdPrefix` which takes the collection name and produces the prefix:

```java
conventions.setTransformClassCollectionNameToDocumentIdPrefix(
  collectionName -> // transform the collection name to the prefix of a identifier, e.g. [prefix]/12
```

Its default behavior is that for a collection which contains one upper character it simply converts it to lower case string. `Users` would be transformed into `users`. For collection names containing more upper characters there will be no change. The collection name: `LineItems` would output the following prefix: `LineItems`.

## FindJavaClassName and FindJavaClass

In the metadata of all documents stored by RavenDB Java Client, you can find the following property which specifies the client-side type. For instance:

```json
{
  "Raven-Java-Type": "com.example.Customer"
}
```

This property is used by RavenDB client to perform a conversion between a Java object and a JSON document stored in a database. A function responsible for retrieving the Java class of an entity is defined by `findJavaClassName` convention:

```java
conventions.setFindJavaClassName(
  clazz -> // use reflection to determinate the type
```

To properly perform the revert conversion that is from a JSON result into a Java object, we need to retrieve the Java class from the `Raven-Java-Type` metadata:

```java
conventions.setFindJavaClass((id, doc) -> {
  return Optional.ofNullable((ObjectNode) doc.get(Constants.Documents.Metadata.KEY))
      .map(x -> x.get(Constants.Documents.Metadata.RAVEN_JAVA_TYPE))
      .map(x -> x.asText())
      .orElse(null);
});
```

## FindIdentityProperty

The client must know where in your entity an identifier is stored to be properly able to transform it into JSON document. It uses the `FindIdentityProperty` convention for that. The default and very common convention is that a property named `Id` is the identifier, so is the default one:

```java
conventions.setFindIdentityProperty(fieldInfo -> "Id".equals(fieldInfo.getName()));
```

You can provide a customization based on the `FieldInfo` parameter to indicate which property or field keeps the identifier. The client will iterate over all object properties and take the first one according to the defined predicate.

## FindIdentityPropertyNameFromCollectionName

It can happen that sometimes the results returned by the server don't have identifiers defined (for example if you run a projection query) however they have `@collection` in metadata.

To perform the conversion into a Java object, a function that finds the identity property name for a given entity name is applied:

```java
conventions.setFindIdentityPropertyNameFromCollectionName(
  collectionName -> "Id"
);
```

## IdentityPartsSeparator

According to the default, convention document identifiers have the following format: `[collectionName]/[identityValue]-[nodeTag]`. The slash character (`/`) separates the two parts of an identifier.
You can overwrite it by using `IdentityPartsSeparator` convention. Its default definition is:

```java
conventions.setIdentityPartsSeparator("/");
```

## See also

- [Document identifier generation](https://docs.ravendb.net/6.2/server/kb/document-identifier-generation.md)
- [Working with document identifiers](https://docs.ravendb.net/6.2/client-api/document-identifiers/working-with-document-identifiers.md)
- [What is a collection?](https://docs.ravendb.net/6.2/client-api/faq/what-is-a-collection.md)
- [Type-specific identifier generation](https://docs.ravendb.net/6.2/client-api/configuration/identifier-generation/type-specific.java.md)
