jpa2.0以上findOne和getOne的區別

 
/**
 * 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對象java

getone:返回實體的引用,代理對象spring

 

實體轉json的過程當中會出錯,用debug查看實體實際上是空,數據是放在代理對象中的,但jackson將實體轉json沒有拿到代理對象,而後產生如下錯誤,這時候json轉換失敗再致使輸出流報錯。json

 

getOne示例:ide

相關文章
相關標籤/搜索