jpa findone 和 getone的区别

来源:互联网 发布:三字头中华 知乎 编辑:程序博客网 时间:2024/06/05 05:42
/**     * 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/