Spring Data JPA getOne()與findById()的區別

getOne()

findById()

Lazily loaded reference to target entity

Actually loads the entity for the given id

Useful only when access to properties of object is not required

Object is eagerly loaded so all attributes can be accessed

Throws EntityNotFoundException if actual object does not exist at the time of access invocation

Returns null if actual object corresponding to given Id does not exist

Better performance

An additional round-trip to database is required

 

鏈接:https://www.javacodemonk.com/difference-between-getone-and-findbyid-in-spring-data-jpa-3a96c3ff

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章