Im mainly looking at the EntityStatics (http://www.hibernate.org/hib_docs/v3/api/org/hibernate/stat/EntityStatistics.html). I can see a lot of fetch, loads and updates and i cant find anywhere that says what the difference between them are.
2 Answers
Working backward through the code, the fetch counter only gets incremented when the entity is retrieved from the datasource (as opposed to any caches) -
protected Object loadFromDatasource(
final LoadEvent event,
final EntityPersister persister,
final EntityKey keyToLoad,
final LoadEventListener.LoadType options) {
final SessionImplementor source = event.getSession();
Object entity = persister.load(
event.getEntityId(),
event.getInstanceToLoad(),
event.getLockMode(),
source
);
if ( event.isAssociationFetch() && source.getFactory().getStatistics().isStatisticsEnabled() ) {
source.getFactory().getStatisticsImplementor().fetchEntity( event.getEntityClassName() );
}
return entity;
}
The load counter was called from too many places to track them all down, but it looks like it gets incremented any time the entity gets loaded, whether from the datasource or the caches.

- 582
- 4
- 17
-
Update? I seem to be getting lots of updates on entities that are immutable. – Sam Mar 04 '09 at 23:05
-
@AlexZuroff I get the opposite, I get a value for loadCount but fetchCount is always zero, how that can be it even occurs if start with empty database so nothing can be retrieved form cache without being retrived form datasource first. – Paul Taylor Jun 13 '19 at 09:11
https://vladmihalcea.com/hibernate-statistics/ This article contains explicit difference between fetch and load counts:
long getEntityLoadCount() It gives you the total number of entities that were loaded (including the one fetched from the first or second-level cache or the database) by the current EntityManagerFactory or SessionFactory. long getEntityFetchCount() It gives you the total number of entities that were fetched from the database by the current EntityManagerFactory or SessionFactory.

- 11
- 1