This is an internal documentation. There is a good chance you’re looking for something else. See Disclaimer.
Custom persisters¶
Custom entity persister¶
The EntityPersister interface contains information how to map an entity to the database table. There is one instance per mapped class. We extend Hibernate’s default implementations to achieve some custom behaviour (CustomEntityPersister).
Entity instantiation¶
By default Hibernate instantiates entity classes by invoking their default constructor.
Entity instantiation is intercepted by overriding EntityPersister#instantiate()
; the instantiation itself is then
delegated to the EntityFactory.
The EntityFactory injects services into
the created entities, tracks new entities and invokes listeners.
Before the entity factory is called it is verified whether the entity to be created belongs to the current Session/Context. This is important as otherwise the wrong Session/Context would be injected by the entity factory.
UpdateCoordinator¶
Hibernate has a default implementation UpdateCoordinatorStandard.
Since hibernate 6 there is an optimization that handlePotentialImplicitForcedVersionIncrement
checks
if it is a simple version update and no other attributes than the version is changed.
However, in such a case the version is incremented but the update user and timestamp was not changed (see cases in UpdatingVersionAndUpdateUserTest
).
ToccoUpdateCoordinatorStandard is a custom implementation
which always return null so that the optimization is disabled, and it works as before with hibernate 5.6.
Custom collection persister¶
There is an instance of a CollectionPersister for every collection. Like with the entity persister, a customized implementation is used.
Filtered collections¶
By always returning true from isAffectedByEnabledFilters()
Hibernate assumes that the collection might be filtered.
Even though we do not use Hibernate’s filter feature we use a similar concept (see Collections).
When filters are enabled certain shortcuts cannot be used by Hibernate (for example removing all entries in a n:n
mapping table, which might wrongfully remove filtered data from the database).
Lazy initialization of CollectionLoader¶
The CollectionLoader instances are also lazily initialized in CustomBatchLoaderFactory for the same reasons as above (memory usage and startup performance).