corda / net.corda.core.node / ServiceHub / withEntityManager

withEntityManager

abstract fun <T> withEntityManager(block: EntityManager.() -> T): T
abstract fun withEntityManager(block: Consumer<EntityManager>): Unit

Exposes the Java Persistence API (JPA) to flows via a restricted EntityManager. This method can be used to persist and query entities which inherit from MappedSchema. This is particularly useful if off-ledger data needs to be kept in conjunction with on-ledger state data.

NOTE: Suspendable flow operations such as send, receive, subFlow and sleep, cannot be called within the lambda.

Parameters

block -

a lambda function with access to an EntityManager.

We want to make sure users have a restricted access to administrative functions. The following methods are blocked:

getTransaction returns a RestrictedEntityTransaction to prevent unsafe manipulation of a flow's underlying database transaction. The following methods are blocked: