28 lines
1.1 KiB
Java
Executable File
28 lines
1.1 KiB
Java
Executable File
package com.ankurm.hibernatedemo.proxy;
|
|
|
|
import jakarta.persistence.EntityManager;
|
|
import jakarta.persistence.PersistenceContext;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
/**
|
|
* Test-only support for docs/11-proxies-and-lazy-initialization.md's OSIV chapter (OsivMaskingTest). Deliberately
|
|
* uses the container-managed, request/transaction-synchronized {@link EntityManager} (via
|
|
* {@code @PersistenceContext}), not a manually created one -- open-in-view only has anything
|
|
* to bind to the request thread when the shared, Spring-managed EntityManager is the one in
|
|
* play.
|
|
*/
|
|
@Service
|
|
public class OsivBookService {
|
|
|
|
@PersistenceContext
|
|
private EntityManager entityManager;
|
|
|
|
@Transactional(readOnly = true)
|
|
public ProxyBook findBook(Long id) {
|
|
// Deliberately does NOT touch getReviews() here -- whether that succeeds later, during
|
|
// JSON serialization in the web layer, is exactly the thing under test.
|
|
return entityManager.find(ProxyBook.class, id);
|
|
}
|
|
}
|