码迷,mamicode.com
首页 > 其他好文 > 详细

jpa2.0以上findOne和getOne的区别

时间:2018-08-22 11:08:58      阅读:575      评论:0      收藏:0      [点我收藏+]

标签:image   data   bug   jpa   示例   panel   option   ret   bubuko   

 
/**
 * Returns a single entity matching the given {@link Example} or {@literal null} if none was found.
 *
 * @param example must not be {@literal null}.
 * @return a single entity matching the given {@link Example} or {@link Optional#empty()} if none was found.
 * @throws org.springframework.dao.IncorrectResultSizeDataAccessException if the Example yields more than one result.
 */
<S extends T> Optional<S> findOne(Example<S> example);
 
 
/**
 * 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)
 * @throws javax.persistence.EntityNotFoundException if no entity exists for given {@code id}.
 */
T getOne(ID id);

 

findone:返回实体的optional对象

getone:返回实体的引用,代理对象

 

实体转json的过程中会出错,用debug查看实体其实是空,数据是放在代理对象中的,但jackson将实体转json没有拿到代理对象,然后产生以下错误,这时候json转换失败再导致输出流报错。

 

getOne示例:

技术分享图片

 

jpa2.0以上findOne和getOne的区别

标签:image   data   bug   jpa   示例   panel   option   ret   bubuko   

原文地址:https://www.cnblogs.com/yinwutuan/p/9516167.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!