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.

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).