PojoRepository is the central class for the Pojo Facade. It supports CRUD operations and search. Each PojoRepository instance operates on only one pojo class. Create new PojoRepository instances based on your custom pojo type like so:
public class MyClass {
@Id
public Integer getMyId() {
...
}
public void setMyId(Integer integer) {
...
}
...
}
...
DatabaseClient client = ...;
PojoRepository<MyClass, Integer> myClassRepo =
client.newPojoRepository(MyClass.class, Integer.class);
Where MyClass is your custom pojo type, and myId is the bean
property of type Integer marked with the @Id
annotation. The @Id annotation can be attached to a
public field or a public getter or a public setter. The bean
property marked with @Id must be a native type or Serializable class and must
contain an identifier value unique across all persisted instances
of that type or the instance will overwrite the persisted instance
with the same identifier.
The current implementation of the Pojo Facade uses Jackson databind for serialization and deserialization to and from json. Thus only classes which can be serialized and deserialized directly by Jackson can be serialized by the Pojo Facade. Every bean property including the one marked with @Id must either expose a public field or both a public getter and a public setter. To test if your class can be directly serialized and deserialized by Jackson, perform the following:
ObjectMapper objectMapper = new ObjectMapper();
String value = objectMapper.writeValueAsString(myObjectIn);
MyClass myObjectOut = objectMapper.readValue(value, MyClass.class);
If that works but the configured objectMapper in the Pojo Facade is different and not working, you can troubleshoot by directly accessing the objectMapper used by the Pojo Facade using an unsupported internal method attached to the current implementation: com.marklogic.client.impl.PojoRepositoryImpl.
ObjectMapper objectMapper = ((PojoRepositoryImpl) myClassRepo).getObjectMapper();
Special handling is provided for bean properties of type
Date and Calendar. The current
implementation of Jackson ObjectMapper changes the timezone to UTC.
The serialized format is ISO 8601 format which is compatible with
xs:dateTime format and can therefore be indexed in the server by a
path range index of type dateTime. However, if you wish to query
using a range index, it is recommended that you modify
serialization to remove the class wrapper by adding a JsonTypeInfo
annotation like so:
@JsonTypeInfo(use=JsonTypeInfo.Id.NONE, include=JsonTypeInfo.As.EXTERNAL_PROPERTY)
public Calendar getMyDateTime();
That way you can query the field directly without needing to traverse the java.util.GregorianCalendar type wrapper. By removing that wrapper, you can create a query like this:
PojoQueryBuilder qb = pojoRepository.getQueryBuilder();
PojoQueryDefinition query = qb.range("myDateTime", Operator.LT, Calendar.getInstance());
If your class has properties which are classes (non-native types) they will be automatically serialized and deserialized, but can only be written, read, or searched as properties of the parent instance. If you wish to directly write, read, or search instances of another class, create and use an instance of PojoRepository specific to that class.
Since PojoRepository stores in JSON format, which limits number precision to 15 significant digits (IEEE754 double precision), you will lose precision on numbers longer than 15 significant digits. If you desire larger numbers with no loss of precision, use Strings to persist those numbers.
longcount()longcount (PojoQueryDefinition query)longcount (PojoQueryDefinition query,
Transaction transaction)longcount (Transaction transaction)longlongcount (String[] collections, Transaction transaction)voidvoiddelete (ID[] ids, Transaction transaction)voidvoiddeleteAll (Transaction transaction)booleanbooleanexists (ID id, Transaction transaction)getDocumentUri (T pojo)longread (ID[] ids, Transaction transaction)read (ID id, Transaction transaction)readAll (long start)readAll (long start,
Transaction transaction)search (long start,
Transaction transaction,
String... collections)search (PojoQueryDefinition query,
long start)search (PojoQueryDefinition query,
long start, SearchReadHandle searchHandle)search (PojoQueryDefinition query,
long start, SearchReadHandle searchHandle,
Transaction transaction)search (PojoQueryDefinition query,
long start, Transaction transaction)voidsetPageLength (long length)voidvoidwrite (T entity,
Transaction transaction)write(T) but in your multi-statement
transaction context.voidwrite (T entity, Transaction transaction,
String... collections)write(T) but also adds your
collections to the persisted instance and performs the write in
your multi-statement
transaction context.voidwrite(T) but also adds your
collections to the persisted instance.entity - the entity instance from which you want
to get the id valueObjectMapper to
generate the serialized JSON format.entity - your pojo instance of the type managed by
this PojoRepositoryResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionwrite(T) but also adds your
collections to the persisted instance.entity - your pojo instance of the type managed by
this PojoRepositorycollections - the collections to add to this
instance in the databaseResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionwrite(T) but in your multi-statement
transaction context.entity - your pojo instance of the type managed by
this PojoRepositorytransaction - the open transaction in which to
write this instanceResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionwrite(T) but also adds your
collections to the persisted instance and performs the write in
your multi-statement
transaction context. .entity - your pojo instance of the type managed by
this PojoRepositorytransaction - the open transaction in which to
write this instancecollections - the collections to add to this
instance in the databaseResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionid - the unique identifier of the pojo (the value
of the field annotated with @Id)ForbiddenUserExceptionFailedRequestExceptionid - the unique identifier of the pojo (the value
of the field annotated with @Id)transaction - the transaction in which this exists
check is participating (Will open a read lock on the document. The
read lock is released when the transaction is committed or rolled
back.)ForbiddenUserExceptionFailedRequestExceptionForbiddenUserExceptionFailedRequestExceptiontransaction - the transaction in which this count
is participating (Will open a read lock on all matched documents.
The read lock is released when the transaction is committed or
rolled back.)ForbiddenUserExceptionFailedRequestExceptioncollections - matches must belong to at least one
of the specified collectionsForbiddenUserExceptionFailedRequestExceptioncollections - matches must belong to at least one
of the specified collectionstransaction - the transaction in which this count
is participating (Will open a read lock on all matched documents.
The read lock is released when the transaction is committed or
rolled back.)ForbiddenUserExceptionFailedRequestExceptionquery - the query to perform to determine the
number of matching instance in the dbForbiddenUserExceptionFailedRequestExceptionquery - the query which results much match
(queries are run unfiltered by default)transaction - the transaction in which this count
is participating (Will open a read lock on all matched documents.
The read lock is released when the transaction is committed or
rolled back.)ForbiddenUserExceptionFailedRequestExceptionids - the ids for the pojo instances to delete
from the serverResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionids - the ids of instances to deletetransaction - the transaction within which to
perform the deleteResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptiontransaction - the transaction within which to
perform the deleteResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionid - the unique identifier of the pojo (the value
of the field annotated with @Id)ResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionid - the unique identifier of the pojo (the value
of the field annotated with @Id)transaction - the transaction in which this read
is participating (will open a read lock on each document matched
that is released when the transaction is committed or rolled
back)ResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionids - the unique identifiers of the pojos (the
values of the field annotated with @Id)ForbiddenUserExceptionFailedRequestExceptionids - the unique identifiers of the pojos (the
values of the field annotated with @Id)transaction - the transaction in which this read
is participating (will open a read lock on each document matched
that is released when the transaction is committed or rolled
back)ForbiddenUserExceptionFailedRequestExceptionstart - the offset of the first document in the
page (where 1 is the first result)getPageLength() instances of
the correct type populated with the persisted data. Since this call
may match a large set, only one page of getPageLength() is returned
just like calls to
search.ForbiddenUserExceptionFailedRequestExceptionstart - the offset of the first document in the
page (where 1 is the first result)transaction - the transaction in which this read
is participating (Will open a read lock on each document matched.
The read lock is released when the transaction is committed or
rolled back.)getPageLength() instances of
the correct type populated with the persisted data. Since this call
may match a large set, only one page of getPageLength() is returned
just like calls to
search.ForbiddenUserExceptionFailedRequestExceptionstart - the offset of the first document in the
page (where 1 is the first result)collections - matches must belong to at least one
of the specified collectionsgetPageLength() instances of
the correct type populated with the persisted data. Since this call
may match a large set, only one page of getPageLength() is returned and
the total estimated number of results is available from PojoPage.getTotalSize().ForbiddenUserExceptionFailedRequestExceptionstart - the offset of the first document in the
page (where 1 is the first result)transaction - the transaction in which this search
is participating (Will open a read lock on each document matched.
The read lock is released when the transaction is committed or
rolled back.)collections - matches must belong to at least one
of the specified collectionsgetPageLength() instances of
the correct type populated with the persisted data. Since this call
may match a large set, only one page of getPageLength() is returned and
the total estimated number of results is available from PojoPage.getTotalSize().ForbiddenUserExceptionFailedRequestExceptionfilteredQuery.query - the query which results much match
(queries are run unfiltered by default)start - the offset of the first document in the
page (where 1 is the first result)getPageLength() instances of
the correct type populated with the persisted data. Since this call
may match a large set, only one page of getPageLength() is returned and
the total estimated number of results is available from PojoPage.getTotalSize().ForbiddenUserExceptionFailedRequestExceptionfilteredQuery.query - the query which results much match
(queries are run unfiltered by default)start - the offset of the first document in the
page (where 1 is the first result)transaction - the transaction in which this search
is participating (Will open a read lock on each document matched.
The read lock is released when the transaction is committed or
rolled back.)getPageLength() instances of
the correct type populated with the persisted data. Since this call
may match a large set, only one page of getPageLength() is returned and
the total estimated number of results is available from PojoPage.getTotalSize().ForbiddenUserExceptionFailedRequestExceptionfilteredQuery.query - the query which results much match
(queries are run unfiltered by default)start - the offset of the first document in the
page (where 1 is the first result)searchHandle - the handle to populate with a
search results payload equivalent to one returned by
QueryManager.searchtransaction - the transaction in which this search
is participating (Will open a read lock on each document matched.
The read lock is released when the transaction is committed or
rolled back.)getPageLength() instances of
the correct type populated with the persisted data. Since this call
may match a large set, only one page of getPageLength() is returned and
the total estimated number of results is available from PojoPage.getTotalSize().ForbiddenUserExceptionFailedRequestExceptionlength - the max number of instance per pageCopyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.