I'm using RavenDB with JAVA ravendb-jvm-client for my app, where existing collection names does'n reflect 'User.java' -> 'Users' convention. Is there a way how to specifiy correct collection name for java beans so java client use this instead of automatic convention? Something similar to @Table annotation for JPA.
I know I can specify collection name for example in queries e.g. session.query(User.class, Query.collection("custUsers"));
... but its very verbose to specify it repeatedly.
You need to use FindCollectionName
convention of the DocumentStore
.
In Java, you can use setFindCollectionName
of the conventions.
By default a collection name is pluralized form of a name of an entity type. For example objects of type
Category
will belong toCategories
collection. However if your intention is to classify them asProductGroups
use the following code:
store.getConventions().setFindCollectionName(clazz -> {
if (Category.class.isAssignableFrom(clazz)) {
return "ProductGroups";
}
return DocumentConventions.defaultGetCollectionName(clazz);
});
Documentation on conventions in general: https://ravendb.net/docs/article-page/4.1/java/client-api/configuration/identifier-generation/global