An interesting unit test is CourseLazyLoadingTest.java which explores lazy loading.
- It outputs the SQL generated by JPA to the log (stdout).
- Shows off the use of
@Transactional
to avoidLazyInitializationException
. - It shows how to use
@Query
to avoid N+1 queries. - Shows using
Hibernate.isInitialized(obj)
to see if obj has been fetched from the database.
run mvn spring-boot:run
to start the application then visit http://localhost:8080/h2-console to view the database
Visit http://localhost:8080/ to view the app