为什么LocalSessionFactoryBean不实现getCurrentSession,同时SessionFactory的实例可以调用该方法? [英] Why doesn't LocalSessionFactoryBean implement getCurrentSession, meanwhile the instance of SessionFactory can invoke the method?

查看:153
本文介绍了为什么LocalSessionFactoryBean不实现getCurrentSession,同时SessionFactory的实例可以调用该方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我对Spring Bean的配置:

 < bean id =sessionFactory
class = org.springframework.orm.hibernate4.LocalSessionFactoryBean>

然后我在DAO层使用它:

  @Resource(name =sessionFactory)
private SessionFactory sessionFactory;

最后是我的问题来自哪里:

  public T getById(int id){
Session session = sessionFactory.getCurrentSession();
return(T)session.get(clz,id);
}

总而言之,我的问题是:

在类org.springframework.orm.hibernate4.LocalSessionFactoryBean中,没有针对 SessionFactory的 method - getCurrentSessio



我追踪 LocalSessionFactoryBean hierachy system through,但是我没有找到方法 getCurrentSession 的实现。



我期待你的答案,非常感谢!

解决方案

工厂bean,如其名称所示,充当工厂。它的作用是创建另一种类型的bean。 Spring注入这个工厂bean的产品,即工厂bean创建的对象。 LocalSessionFactoryBean 产生 SessionFactory



有关更多信息,请阅读文档


This is my configuration for Spring Bean:

<bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

And then I use it in DAO layer like this:

    @Resource(name = "sessionFactory")
    private SessionFactory sessionFactory;

At last it's where my question come from:

    public T getById(int id) {
        Session session = sessionFactory.getCurrentSession();
    return (T) session.get(clz, id);
    }

In all, my question is that:

In class "org.springframework.orm.hibernate4.LocalSessionFactoryBean",there is no implementation for SessionFactory's method -- "getCurrentSessio".

I traced LocalSessionFactoryBean's hierachy system through, but I didn't find the implementation for the method "getCurrentSession".

I'm expecting your answers, thanks very much!

解决方案

A factory bean, as its name indicates, acts as a factory. Its role is to create a bean of another type. Spring injects the product of this factory bean, i.e. the object that the factory bean has created. A LocalSessionFactoryBean produces a SessionFactory.

For more information, read the documentation.

这篇关于为什么LocalSessionFactoryBean不实现getCurrentSession,同时SessionFactory的实例可以调用该方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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