jpa findone 和 getone的区别
/**
* Retrieves an entity by its id.
*
* @param id must not be {@literal null}.
* @return the entity with the given id or {@literal null} if none found
* @throws IllegalArgumentException if {@code id} is {@literal null}
*/
T findOne(ID id);
/**
* Returns a reference to the entity with the given identifier.
*
* @param id must not be {@literal null}.
* @return a reference to the entity with the given identifier.
* @see EntityManager#getReference(Class, Object)
*/
T getOne(ID id);
注意getOne是“Returns a reference“
findOne比getOne更通用。推荐使用findOne。具体原因如下:
it"s just that findOne(ID)
is more generic than the more specialised getOne(ID)
. Which one you use is up to you and your project but I would personally stick to the findOne(ID)
as it makes your code less implementation specific and opens the doors to move to things like MongoDB etc. in the future without too much refactoring :)
欢迎关注橙子博客微信公众号:chengziboke888

查看原文:http://zccbbg.top/2017/05/24/111-2/
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: MongoDB中的findOne()方法的用法
- 下一篇: 如何在同一窗口打开多个终端并实现快捷键切换