How it works · Persistence

Declare the business fields; the base class does the rest

An entity extends a Chenile base class and holds only business fields. Before every insert and update the base class fills in who changed it, when, for which tenant and whether it is test data, gives it an id, and guards it with a version column.

Persistence: entities that fill in their own audit fields A service saves an entity that declares only business fields. Before the insert, the Chenile base class stamps the creation and modification times, the user, the tenant and the test flag from the request context, and an id: built from the request id, produced by a named strategy bean, or left to the database. The routing DataSource sends the connection to the tenant's database. A variant shows two concurrent updates: the version column lets the first win and refuses the second. OrderServiceImplorderRepository.save(order) Spring Data JPAOrderRepository BaseJpaEntity id createdTime · lastModifiedTime createdBy · lastModifiedBy tenant testEntity version (@Version) @PrePersist · from the request context IDGeneratorprefix-requestId-counter ContextContaineruser · tenant · test mode routing DataSourceone pool per tenant acme · table orders (no row yet) the entity extends a Chenile base class; the service sets only business fields
id
scenario
view
Step 1

Exchange

Payload

Audit by default

Created and modified times, the user and the tenant come from the request context in a JPA callback, so no service writes them and none forgets them.

Ids your way

String ids built from the request id, so a replayed request makes the same ids; numeric ids from a strategy bean you name; or ids the database assigns.

No lost updates

Every entity carries a version. Of two concurrent updates the first wins and the second fails, instead of silently overwriting it.