在休眠统计什么是加载和获取之间的区别 [英] In hibernate statistics whats the difference between load and fetch

查看:149
本文介绍了在休眠统计什么是加载和获取之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我主要看着EntityStatics( http:/ /www.hibernate.org/hib_docs/v3/api/org/hibernate/stat/EntityStatistics.html )。我可以看到很多抓取,加载和更新,我无法找到任何说明它们之间有什么区别的地方。 解决方案

在代码中反向工作时,只有在从数据源(而不是任何缓存)检索到实体时,提取计数器才会增加 -

  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()&& amp; source.getFactory()。getStatistics()。isStatisticsEnabled()){
source.getFactory()。getStatisticsImplementor()。fetchEntity event.getEntityClassName());
}

返回实体;
}

加载计数器在太多的地方被调用来追踪它们,但看起来无论何时加载实体,无论是来自数据源还是缓存,它都会增加。


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.

解决方案

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.

这篇关于在休眠统计什么是加载和获取之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆