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.
In session. load(), Hibernate will not hit the database (no select statement in output) to retrieve the Stock object, it will return a Stock proxy object – a fake object with given identify value. In this scenario, a proxy object is enough for to save a stock transaction record.
The load() method is quicker than the get() method.
From the output it's clear that get() returns the object by fetching it from database or from hibernate cache whereas load() just returns the reference of an object that might not actually exists, it loads the data from database or cache only when you access other properties of the object.
SessionFactory is to create and manage Sessions . Session is to provide a CRUD interface for mapped classes, and also access to the more versatile Criteria API .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With