title: What is the use of @Transactional with JPA and Hibernate?
body: <p>I'm learning about how to create REST API with JPA and Hibernate and a MySQL database and I see this @Transactional annotation. Can someone explain what is the use of this annotation? </p>
  
  <p>For example I have this simple DAO class:</p>
  
  <pre><code>@Repository
  public class EmployeeDAOHibernateImpl implements EmployeeDAO {
  
      // define field for entitymanager
      private EntityManager entityManager;
  
      // set up constructor injection
      @Autowired
      public EmployeeDAOHibernateImpl(EntityManager entityManager) {
          this.entityManager = entityManager;
      }
  
      @Override
      @Transactional
      public List&lt;Employee&gt; findAll() {
  
          // get the current hibernate session
          Session currentSession = entityManager.unwrap(Session.class);
  
          // create a query
          Query&lt;Employee&gt; theQuery = 
                  currentSession.createQuery("from Employee", Employee.class);
  
          // execute query and get result list
          List&lt;Employee&gt; employees = theQuery.getResultList();
  
          // return the results
          return employees;
      }
  
  }
  </code></pre>
  
  <p>You can see the @Transactional used for findAll() method, but if I delete this @Transactional I get the same output... then what is the use of this @Transactional? </p>