开发者

How update operation works in hibernate?

开发者 https://www.devze.com 2023-04-11 01:44 出处:网络
As per hibernate documentation , below is the definition of update开发者_开发知识库 operation

As per hibernate documentation , below is the definition of update开发者_开发知识库 operation

void update(Object object) throws HibernateException Update the persistent instance with the identifier of the given detached instance. If there is a persistent instance with the same identifier, an exception is thrown. This operation cascades to associated instances if the association is mapped with cascade="save-update".

I have a question on statement If there is a persistent instance with the same identifier, an exception is thrown. . I think when it is saying If there is a persistent instance with the same identifier it means if the session (in which we doing update operation) already contains persistent instance with the same identifier, exception will be thrown. But if the second level cache contains the persistent instance with the same identifier, update operation will update the object., it wont throw any exception Right?


No, the statement tells about the Session, not the second level cache. Second level cache work at session factory level and it exists as long as the session factory is alive. And if object with same identifier attached with the session(not second level cache), then only the exception will be thrown. If not, then it will update the object in database as well as second level cache.


Agreed. The update should not throw an exception if an instance with the same identifier is in the second level cache.

The sentence you highlighted isn't very clear but I think you're correct in your assumption. Perhaps you could comment on the http://jboss.org forums and see if they can clarify the wording, maybe even improve it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号