title: Stateless session in Spring Boot
body: <p>We have some REST calls which performs quite massive operations on data (but not via Spring-Data). Because of that we would like to have Stateless Session for them.</p>
  
  <p>Question is how to make it properly in Spring Boot with Hibernate and JPA?
  Because when I make simple test where I call some repository :</p>
  
  <pre><code>@Repository 
  public class HelloRepository {
  
    @PersistenceContext   
    private EntityManager entityManager;
  
    public boolean checkIfTransactionIsOpened() {
      return entityManager.unwrap(Session.class).isOpen();   
    }
  
  }
  </code></pre>
  
  <p>it gives me always true. I have feeling that session there should not be opened as I want to use Stateless Session.</p>
  
  <p>Controller and Service do not do anything special. No @Transactional annotations etc:</p>
  
  <pre><code>@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&lt;Boolean&gt; sayHello() {
      return ResponseEntity.ok(helloService.checkIfTransactionIsOpened());
    }
  }
  
  @Service
  public class HelloService {
    @Autowired
    private HelloRepository helloRepository;
  
    public boolean checkIfTransactionIsOpened() {
      return helloRepository.checkIfTransactionIsOpened();
    }
  }
  </code></pre>
  
  <p>So question is: HOW to inform my app "please do not open session there I want to use stateless session"?</p>