休眠:sessionFactory.openSession()VS sessionFactory.getCurrentSession()

罗希特·贾恩(Rohit Jain)

我正在尝试在Spring 4(Java配置)中制作一个Web应用程序。我使用postgres作为数据库,使用C3P0作为连接池。我所有的数据库事务都在postgres存储过程/函数中进行。我正在使用Hibernate @ NamedNativeQueries调用存储过程。

我有两个问题:1.我的应用程序将同时有多个用户登录。所以我应该使用sessionFactory.openSession()或sessionFactory.getCurrentSession()来获取休眠会话吗?2.我应该在Spring MVC4中使用Hibernate调用存储过程或建立支持吗?我知道这两种方式,但是我比休眠方式更省力,因为与春季方式相比,它需要的工作量更少,但是我觉得休眠方式使我的应用程序变慢但不确定。

请帮助我找到这些问题的答案。

胜利者加莱

回答第一个问题:您应该为每个用户连接一个会话。例如,如果您在servlet上下文中,则可以有一个servlet过滤器来为sessionFactory.openSession()每个servlet线程调用

回答第二个问题:性能和优化不是一种感觉。如果您feel冬眠的速度很慢,请对其进行测量,然后尝试找出原因。您必须测量它放慢的地方。您也可以通过一个简单的示例尝试这两种解决方案,并知道您会觉得更舒适。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

EntityManager的SessionFactory引发异常

hibernate SessionFactory.openSession()是否等待池中的数据库连接可用

可以休眠扫描软件包以自动创建SessionFactory吗?

休眠SessionFactory与EntityManagerFactory

Hibernate SessionFactory与JPA EntityManagerFactory

休眠openSession()vs getCurrentSession()

Hibernate的Sessionfactory.getCurrentSession()和SessionFactory.openSession()的区别

sessionfactory.openSession()和sessionfactory.openStatelessSession()之间的区别?

java.lang.NoSuchMethodError:org.hibernate.SessionFactory.openSession()Lorg / hibernate / classic / Session

Hibernate 4中的SessionFactory.openSession(Connection)

在春季了解SessionFactory

使用Mockito模拟休眠的SessionFactory时出现问题

NoSuchMethodError:org.hibernate.SessionFactory.getCurrentSession()

休眠不创建sessionFactory bean

使用_sessionFactory.getCurrentSession()检索用户会话中的当前用户ID。冬眠的

在Hibernate中使用SessionFactory.getCurrentSession()时获取Connection对象

正确配置以模拟Hibernate的sessionFactory.getCurrentSession()

无法使用Spring 5自动连接休眠5 sessionfactory

春季错误-NoSuchBeanDefinitionException:SessionFactory

Hibernate SessionFactory与Spring LocalSessionFactoryBean

加载sessionFactory的问题

SessionFactory休眠错误(Spring MVC项目)

未为类型SessionFactory定义方法getCurrentSession()

初始SessionFactory创建失败

休眠,sessionFactory.openSession挂起

Hibernate OpenSession()与GetCurrentSession()

Hibernate + Spring SessionFactory配置

何时使用OpenSession()和GetCurrentSession()

Spring + Hibernate:sessionFactory.getCurrentSession()导致NullPointerException