if (tx!=null && tx.getLocalStatus() != LocalStatus.ROLLED_BACK) tx.rollback(); logger.error("Error {}.", e.getMessage());
@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public Integer fillData(Integer number) throws Exception{ Session sess = sessionFactory.getCurrentSession(); Integer sumNumbers = -1; Transaction tx = null; try{ tx = sess.beginTransaction(); emptyTable(); for(int i = 0; i < number; i++){ Random n = new Random(); Integer x = n.nextInt(100)+1; DataModel dm = new DataModel(i+1, x); addData(dm); } sumNumbers = getSumNumber(); tx.commit(); } catch (Exception e) { if (tx!=null && tx.getLocalStatus() != LocalStatus.ROLLED_BACK) tx.rollback(); e.printStackTrace(); } finally { //will be closed in controller sess.close(); } return sumNumbers; }