Spring Data JPA getOne()和findOne()的区别

使用getOne()获取的是一个空的对象;用findOne则可以获取想要的;
参见源码

/**
 * 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);

/**
 * 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);
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,099评论 19 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,956评论 25 709
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,991评论 6 342
  • 初中、高中、大学时期是我情感波动最大的时期,我的同学也有一些波动很大,我们轰隆隆的心理变化和遭遇的伤痛是这一辈子...
    小英雄200218阅读 198评论 0 0
  • 时常想起这一刻的我,下一刻的我,还有过去的我。 过去细微的变化,会塑造现在不同的我。我的过去,我的将来,中间有...
    萌龙在天阅读 217评论 0 1