1
データに対してかなりの量の操作(Springデータ経由ではない)を実行するREST呼び出しがいくつかあります。そのため、私たちは彼らのためにステートレスセッションを開催したいと考えています。Spring起動時のステートレスセッション
質問は、HibernateとJPAを使用してSpringブートで正しく設定する方法ですか? 私はいくつかのリポジトリを呼び出す簡単なテスト作るときので:
@Repository
public class HelloRepository {
@PersistenceContext
private EntityManager entityManager;
public boolean checkIfTransactionIsOpened() {
return entityManager.unwrap(Session.class).isOpen();
}
}
それは常にtrueを私に与えます。私はステートレスセッションを使用したいので、そこにセッションを開くべきではないと感じています。
コントローラとサービスは特別なことをしません。ノー@Transactional注釈など:
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
@RestController
public class HelloRest {
@Autowired
private HelloService helloService;
@GetMapping("/hello")
public ResponseEntity<Boolean> sayHello() {
return ResponseEntity.ok(helloService.checkIfTransactionIsOpened());
}
}
@Service
public class HelloService {
@Autowired
private HelloRepository helloRepository;
public boolean checkIfTransactionIsOpened() {
return helloRepository.checkIfTransactionIsOpened();
}
}
そこで質問です:どのように私のアプリ「私はステートレスセッションを使用したいがオープンセッションをしないでください」を知らせるために?