Files
hibernate-demo/src/test/java/com/ankurm/hibernatedemo/proxy/OsivBookController.java
T

28 lines
968 B
Java
Executable File

package com.ankurm.hibernatedemo.proxy;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
/**
* Test-only support for docs/11-proxies-and-lazy-initialization.md's OSIV chapter (OsivMaskingTest). Returns the
* managed entity directly (not a DTO) ON PURPOSE -- Jackson's serialization of
* {@code getReviews()} on the response-writing thread is the exact moment open-in-view either
* saves you (session still bound, proxy initializes) or doesn't (session long closed,
* LazyInitializationException).
*/
@RestController
public class OsivBookController {
private final OsivBookService service;
public OsivBookController(OsivBookService service) {
this.service = service;
}
@GetMapping("/osiv/books/{id}")
public ProxyBook getBook(@PathVariable Long id) {
return service.findBook(id);
}
}