在Spring 3之前注入Hibernate会话的最佳方法

在Spring 3之前注入Hibernate会话的最佳方法,第1张

在Spring 3之前注入Hibernate会话的最佳方法

在Spring参考建议这种用法

public class ProductDaoImpl implements ProductDao {    private SessionFactory sessionFactory;    public void setSessionFactory(SessionFactory sessionFactory) {        this.sessionFactory = sessionFactory;    }    public Collection loadProductsByCategory(String category) {        return this.sessionFactory.getCurrentSession()     .createQuery(         "from test.Product product where product.category=?")     .setParameter(0, category)     .list();    }}

这样,您的类就不会对Spring有任何依赖,您只需使用普通的Hibernate。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5505918.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-13

发表评论

登录后才能评论

评论列表(0条)

保存