withEntityManager

open override fun <T> withEntityManager(block: <Error class: unknown class>.() -> T): T
open override fun withEntityManager(block: Consumer<<Error class: unknown class>>)

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:

  • close()

  • unwrap(cls: Class?)

  • getDelegate(): Any

  • getMetamodel()

  • joinTransaction()

  • lock(entity: Any?, lockMode: LockModeType?)

  • lock(entity: Any?, lockMode: LockModeType?, properties: MutableMap?)

  • setProperty(propertyName: String?, value: Any?)

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

  • begin()

  • commit()

  • rollback()