https://github.com/mtumilowicz/spring-data-getone
The main goal of this project is to show how getOne works internally.
https://github.com/mtumilowicz/spring-data-getone
jpa spring-data spring-data-jpa
Last synced: about 1 month ago
JSON representation
The main goal of this project is to show how getOne works internally.
- Host: GitHub
- URL: https://github.com/mtumilowicz/spring-data-getone
- Owner: mtumilowicz
- Created: 2018-08-10T19:03:56.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-24T22:13:55.000Z (almost 8 years ago)
- Last Synced: 2025-10-20T02:15:44.027Z (9 months ago)
- Topics: jpa, spring-data, spring-data-jpa
- Language: Java
- Homepage:
- Size: 77.1 KB
- Stars: 2
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://travis-ci.com/mtumilowicz/spring-data-getone)
# spring-data-getone
The main goal of this project is to show how `getOne` works internally.
# preface
According to JPA specification, we have two methods:
* `EntityManager.find()` - query the database.
* `EntityManager.getReference()` - load proxy (no database query),
throws `EntityNotFoundException` if entity doesn't exist in the database
(when synchronization with the database occurs).
# spring data
* `Optional findById(ID id)` - eager loading (internally `EntityManager.find()`)
* `T getOne(ID id)` - lazy loading (internally `EntityManager.getReference()`)
# project description
We enable query logging (`application.properties`):
```
spring.jpa.properties.hibernate.show_sql=true
```
and in `AppRunner` we simulate basic behaviour.
# remarks
If you use `getOne` it loads proxy, but at first reference to any field -
provider loads the actual entity from database - so you have to still be
in the persistence context.
# tests
**Coverage**: `96%`