title: What are advantages of using @Transactional(readOnly = true)?
body: <p>I am beginner and as I understand <code>@Transactional</code> simply make sure that all the internal work of a class or method annotated with <code>@Transactional</code> will be wrapped in one transaction and all of the calls from external sources will create a new transaction but why do we actually need these annotations in Repository below and what are advantages of using it with <code>readOnly = true</code> in common cases? This is Spring pet-clinic example application using <strong>Spring</strong> &amp; <strong>Hibernate</strong> (<a href="https://github.com/spring-projects/spring-petclinic" rel="noreferrer">https://github.com/spring-projects/spring-petclinic</a>).</p>
  
  <pre><code>/**
   * Repository class for &lt;code&gt;Pet&lt;/code&gt; domain objects All method names are compliant with Spring Data naming
   * conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
   *
   * @author Ken Krebs
   * @author Juergen Hoeller
   * @author Sam Brannen
   * @author Michael Isvy
   */
  public interface PetRepository extends Repository&lt;Pet, Integer&gt; {
  
      /**
       * Retrieve all {@link PetType}s from the data store.
       * @return a Collection of {@link PetType}s.
       */
      @Query("SELECT ptype FROM PetType ptype ORDER BY ptype.name")
      @Transactional(readOnly = true)
      List&lt;PetType&gt; findPetTypes();
  
      /**
       * Retrieve a {@link Pet} from the data store by id.
       * @param id the id to search for
       * @return the {@link Pet} if found
       */
      @Transactional(readOnly = true)
      Pet findById(Integer id);
  
      /**
       * Save a {@link Pet} to the data store, either inserting or updating it.
       * @param pet the {@link Pet} to save
       */
      void save(Pet pet);
  
  }
  </code></pre>