Skip to content
Bluetape4k docs1.12

StatelessSession, batches, and events

Latest stable Based on Bluetape4k release 1.12.1

withBatchSize temporarily applies a positive JDBC batch size and restores the previous value. It does not bound the first-level cache, so bulk inserts still need periodic flush and clear.

session.withBatchSize(100) {
entities.forEachIndexed { index, entity ->
persist(entity)
if ((index + 1) % 100 == 0) { flush(); clear() }
}
}

In 1.12.1, failure to read the old value falls back to zero and restoration failure is warning-only.

SessionFactory.withStateless owns the stateless session, transaction, commit or rollback, and close. StatelessSession omits the first-level cache, dirty checking, cascading, collection persistence, and JPA entity listeners.

sessionFactory.withStateless { stateless ->
masters.forEach { master ->
stateless.insert(master)
master.details.forEach(stateless::insert)
}
}

Insert related entities explicitly.

The 1.12.1 StatelessSessionFactoryBean binds its resource under the SessionFactory key and can collide with an existing JPA transaction resource. The dedicated-key fix came after the release. Prefer explicit SessionFactory.withStateless over the injected Spring proxy in 1.12.1.

registerEventListener adds Hibernate listeners; the misspelled registEventListener is deprecated. Built-in logging listeners can print full entities at trace level. Keep credentials and personal data out of entity string output, and use a durable audit design when audit delivery matters.

Terminal window
./gradlew :bluetape4k-hibernate:test --tests '*StatelessSessionStandaloneTest'
./gradlew :bluetape4k-hibernate:test --tests '*SessionSupportTest'