简体   繁体   English

Hibernate Save()-'Save Method'是什么意思,save()在事务之外工作?

[英]Hibernate Save() - 'Save Method' what is it mean by save() work outside the transaction?

Well when I read about different between hibernate 'Persist' and 'Save' method, Many articles has notably highlighted that "Save method can execute outside the transaction boundary" 好吧,当我了解到休眠的“ Persist”和“ Save”方法之间的区别时,很多文章特别强调了“ Save方法可以在事务边界之外执行”
This statement made me really confused and I read fair enough articles to understand the real meaning of this, but no luck !!! 这句话让我感到非常困惑,我读了足够多的文章来理解它的真正含义,但是没有运气! now I have following points to clarify. 现在我有几点要澄清。

Question 1 问题1

is this true?? 这是真的?? If true then 如果为真

Question 2 问题2

[assuming transaction means physical DB transaction] [假设交易是指物理数据库交易]

As far as I know no database execution can happen with out transaction, then what it mean by outside of transaction boundary? 据我所知,没有事务就不会执行数据库,那么在事务边界之外意味着什么呢?

Question 3 问题3

[assuming transaction means logical transaction] [假设交易是逻辑交易]

According materials I refereed, 'session' lay out the logical transaction. 根据我引用的材料,“会话”列出了逻辑事务。 so even if it use persist() or save() to persist data it will flush and commit to only after when explicitly commit or session.flush or closing the session. 因此,即使它使用persist()或save()持久化数据,它也将仅在显式提交或session.flush或关闭会话之后才刷新并提交。

since session is the logical transaction and no execution can be perform without a session, then what is it mean by save() work outside transaction? 由于会话是逻辑事务,没有会话就无法执行,那么在事务外部进行save()工作意味着什么?

If someone can give me a clear detailed answer it would be a great help Thanks a lot !!! 如果有人可以给我一个清晰详细的答案,那将是一个很大的帮助。非常感谢!

This is a good article that is too long to copy: https://www.journaldev.com/3481/hibernate-session-merge-vs-update-save-saveorupdate-persist-example . 这是一篇很好的文章,太长了,无法复制: https : //www.journaldev.com/3481/hibernate-session-merge-vs-update-save-saveorupdate-persist-example In essence: 在本质上:

Q1: Yes, it is true. 问题1:是的,这是真的。 It means you can call session.save(object) without first having done session.beginTransaction() . 这意味着您无需先完成session.beginTransaction()即可调用session.save(object) session.beginTransaction() You must still have an open session. 您必须仍然有一个开放的会话。

Q2: Transaction means Hibernate's transaction, presumably the session will still use a transaction towards the database but a very short one and perhaps implicit (auto-commit). Q2:事务意味着Hibernate的事务,大概会话仍将使用对数据库的事务,但是事务很短,甚至是隐式的(自动提交)。

Q3: It means outside of a Hibernate transaction started by beginTransaction . Q3:这意味着在由beginTransaction启动的Hibernate事务之外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM