Liferay研究之廿二:怪异的updateUser(user)方法

今天有网友问到关于Liferay的updateXxxx(entity)方法比较怪异的问题,比如UserPersistanceImpl.update(user, false).

光看源码,好像根本就没有执行save or saveOrUpdate或者merge等Hibernate的方法,那又是如何保存的呢?

分析了一下,做了一个简单的research,发现还真是很有意思的。

http://www.liferay.com/web/guest/community/forums/-/message_boards/message/569279

其中Ray提到:smilingleo原创, www.smilingleo.cn

Not true! We use the parameterless call everywhere in our core
services... and the reason is DOES work is because the object IS in the
hibernate session and flushing the changes is handled by hibernate...

using merge() basically tell hibernate NOT TO WAIT for it's natural
Flush to be invoked. merge() forces a cache flush...

也就是说,只要执行一个flush()方法就可以实现物理层与内存中的同步了,而不再需要更加耗费资源的merge方法了。smilingleo原创, www.smilingleo.cn

此外,还涉及到一些Spring的事务的知识,可以查阅一下《Spring in Action》第5章内容,或者网上一些文章,比如:

http://blog.csdn.net/luying777/archive/2008/04/29/2344557.aspx

http://itfuture.javaeye.com/blog/182201

这里面还真的很有研究的必要的。

在Liferay中,一般对一个entry进行update操作时,都是通过XXXLocalServiceUtil.getEntry(entryId)获取到entry的实例,这个时候entry是persistent的。所以,在更新时不再需要saveOrUpdate或者merge,通过flush就可以实现更新了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值