In my test case I have transactional method that creates user and then invokes async method in different thread that retrieves this user from database. In code below the user cannot be found in db and dao returns null. How to be sure that data will be there for different threads? It seems that flushing does not help. Do I need to manually commit? Setting isolation level to READ_UNCOMMITED also does not help.
@Transactional public void createUser() { User user = new User(); user.setLogin("test"); userService.save(user); userService.flush(); logger.debug("New user id {}", user.getId()); //id=1 transactionalService.getUser(user.getId()); }
TransactionalService
@Async @Transactional public void getUser(Long id) { User user = userDao.getById(id); assertNotNull(user); }