我对休眠有一个简单的问题:
真的,事务持续时间比休眠中的会话长吗?
@Controller
public class VacancyMenuController extends AbstractController{
...
@RequestMapping("/path")
public String delete(Model model){
//here session opens and transaction starts ?
vacancyService.delete(vacancy.getId());
//here transactions commit and session close ?
sessionFactory.getCurrentSession().flush();
//here session opens and transaction starts ?
Vacancy vacancyFromDb = vacancyService.findById(vacancy.getId());
//here transactions commit and session close ?
sessionFactory.getCurrentSession().flush();
}
}
@TransactionConfiguration(defaultRollback = false)
@ContextConfiguration(locations = { "classpath:/test/BeanConfig.xml" })
public class AbstractServiceTest extends AbstractTransactionalJUnit4SpringContextTests{
....
@Test
public void delete(){
//here session opens and transaction starts
vacancyService.delete(vacancy.getId());
sessionFactory.getCurrentSession().flush();
Vacancy vacancyFromDb = vacancyService.findById(vacancy.getId());
sessionFactory.getCurrentSession().flush();
Assert.assertNull(vacancyFromDb);
//here transactions commit and session close
}
}
在我的评论上方的代码片段中是对的吗?