Hibernate:加载vs获取 [英] Hibernate: load vs get

查看:93
本文介绍了Hibernate:加载vs获取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个很多时候被描述的常见问题。
但是我仍然无法得到一些东西 - 那么性能呢?哪种方法更快?



实际上,我需要一个简单的事情:页面发出POST请求:id = 0,name ='John'。服务器端脚本应该检查id = 0,然后在数据库中创建一个新记录,否则更新现有的。



我认为get()对我更有用因为在DB中不存在记录的情况下它将返回NULL,而load()可以返回一些temproray对象。我是对的吗?
谢谢

解决方案

这是Hibernate论坛中等效问题的链接,这是我的谷歌query( Hibernate load vs get ): https://论坛

其中包括以下内容:


blockquote>

load()方法较旧;由于用户
请求,get()被添加到Hibernate的API中。差异是微不足道的:


如果load()在缓存或数据库中找不到对象,则抛出异常
。 load()方法永远不会返回null。如果找不到对象,则get()方法返回
null。



I know that this is a common question that was described a lot of times. But still I can't get some thing - what about performance? Which method is faster?

Actually, I need a simple thing: the page makes a POST-request: id=0, name='John'. The server-side script should check if id=0, then create a new record in DB, otherwise update existing.

I think that get() is more usefull for me because it will return a NULL in case of record is not exists in DB, while load() can return some temproray object.. Am I right? Thank you

解决方案

Here's a link to the equivalent question in the Hibernate forum which was the first result in my google query (Hibernate load vs get): https://forum.hibernate.org/viewtopic.php?p=2387456

There it states the following:

The load() method is older; get() was added to Hibernate’s API due to user request. The difference is trivial:

If load() can’t find the object in the cache or database, an exception is thrown. The load() method never returns null. The get() method returns null if the object can’t be found.

这篇关于Hibernate:加载vs获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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