休眠批处理过程:无状态会话VS常规会话本机查询 [英] Hibernate Batch process : Stateless Session VS Regular Session Native Query

查看:100
本文介绍了休眠批处理过程:无状态会话VS常规会话本机查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,到目前为止,使用批处理时首选无状态会话,因为它只会分离执行该处理的对象,从而使持久上下文和缓存是空闲的,因此批处理是这种情况的闲置情况,通常称为无格式会话. JDBC查询引擎,查询立即转换为SQL查询. 引用自: https://stackoverflow.com/a/14174403/1460591

As I understand so far stateless sessions are preferred when using batch processes since It will just detach objects doing the process So that persistent context and cache would be free so batch processes are the idle case for that, It is commonly known as plain JDBC Query Engine with queries translated to SQL queries immediately. Referenced from : https://stackoverflow.com/a/14174403/1460591

另一方面,我了解到本机查询的功能相同,我看到的一个区别是无状态会话可以将结果映射到实体,而本机查询只有在明确提供了映射器之后才能这样做.

On the other hand, I learned that native queries do the same the one difference I see is that the stateless session can map the result to an entity, Native queries don't do that until mapper is explicitly provided.

那么还有其他区别吗?从性能的角度来看,批处理时更好吗?

So is there another difference and from a performance point of view which is better when doing batch processes?

推荐答案

如果通过批处理的意思是通过SQL查询本身(例如UPDATE things SET daily_quota=15)修改数据库服务器中的实体,则本机SQL会更快.但是,在这种情况下,您没有加载任何实体,因此这似乎并没有引起您的疑问.

If by batch processing you mean modifying entities in the database server via the SQL query itself (e.g. UPDATE things SET daily_quota=15) then the native SQL is faster. However, in this case, you aren't loading any entities so this doesn't really seem to jive with your question.

如果通过批处理意味着修改程序中的实体(例如,加载所有Thing实例,将dailyQuota属性修改为15并编写更新,那么您将需要无状态会话.

If by batch processing you mean modifying entities in your program (e.g. load all Thing instances, modify the dailyQuota attribute to 15 and write an update then you will want a stateless session.

使用本机查询检索对象不会为您提供任何修改对象的机制.您仍然需要将其合并回持久性上下文并刷新这些更改.完成此操作(假设您没有无状态会话)后,它将使用经典的更改检测和检测功能.缓存保持刷新机制.

Using a native query to retrieve the objects doesn't give you any mechanism to modify the object. You still need to merge it back to the persistence context and flush those changes. Once you do this (assuming you don't have a stateless session) then it will use the classic change-detecting & cache-keeping flush mechanism.

另一方面,无状态会话为您提供了一种修改程序中实体的方法,而无需强迫ORM层通过缓慢变化检测过程.

A stateless session on the other hand gives you a way to modify entities in your program without forcing the ORM layer to go through the slow change detection process.

这篇关于休眠批处理过程:无状态会话VS常规会话本机查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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