Skip to content
Martin Ledvinka edited this page Nov 13, 2025 · 1 revision

JOPA transactions try to follow the semantics of JPA transactions as closely as possible. This, for example, means that:

  • All managed entities become detached on transaction commit/rollback
  • Any changes to a managed entity are propagated to the underlying repository on transaction commit
    • For example, loading an entity during a transaction and setting it attribute values is enough to propagate the changes into the repository, it is not necessary to call EntityManager.merge.

Read-only Transaction

JOPA supports read-only transactions by optimizing the persistence context to:

  • Not track/calculate changes on managed entities on commit
  • Throwing exceptions when attempting to call modification operations such as persist/merge
  • Setting read-only mode on the underling OntoDriver Connection, allowing for lower-level optimizations

Enabling Read-only Transaction Mode

Read-only mode is set on EntityManager level by passing read_only as value of the property cz.cvut.kbss.jopa.transactionMode (JOPAPersistenceProperties.TRANSACTION_MODE). For example,

EntityManagerFactory emf = // get EMF
EntityManager readOnlyEm = emf.createEntityManager(Map.of("cz.cvut.kbss.jopa.transactionMode", "read_only"));

Clone this wiki locally