title: getting package org.springframework.transaction.annotation does not exist error while packaging app
body: <p>I am quite new in Spring world. I have developed a DAO using Spring 3.2 and Hibernate 4.1.9 but I have noticed a strange thing.</p>
  
  <p>All the used dependencies related to Spring belong to the 3.2.1 version, except that related to the <strong>spring-aop</strong> module. For this module I have to use the 3.2.0 version because if I use the 3.2.1 in the dao class implementation don't find this import: <strong>org.springframework.transaction.annotation.Transactional</strong></p>
  
  <p>This is my original <strong>pom.xml</strong> file (that work well):</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;org.andrea.myexample&lt;/groupId&gt;
      &lt;artifactId&gt;HibernateOnSpring&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;name&gt;HibernateOnSpring&lt;/name&gt;
      &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;3.8.1&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;!-- Dipendenze di Spring Framework --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
              &lt;version&gt;3.2.1.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
              &lt;version&gt;3.2.1.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
              &lt;version&gt;3.2.1.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-context-support&lt;/artifactId&gt;
              &lt;version&gt;3.2.1.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
  
          &lt;dependency&gt;   &lt;!-- Usata da Hibernate 4 per LocalSessionFactoryBean --&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
              &lt;version&gt;3.2.0.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- Dipendenze per AOP --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;cglib&lt;/groupId&gt;
              &lt;artifactId&gt;cglib&lt;/artifactId&gt;
              &lt;version&gt;2.2.2&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- Dipendenze per Persistence Managment --&gt;
  
          &lt;dependency&gt;    &lt;!-- Apache BasicDataSource --&gt;
              &lt;groupId&gt;commons-dbcp&lt;/groupId&gt;
              &lt;artifactId&gt;commons-dbcp&lt;/artifactId&gt;
              &lt;version&gt;1.4&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;    &lt;!-- MySQL database driver --&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;version&gt;5.1.23&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;    &lt;!-- Hibernate --&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
              &lt;version&gt;4.1.9.Final&lt;/version&gt;
          &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>and this is my <strong>PersonDAOImpl</strong> class (the class that implement my concrete DAO):</p>
  
  <pre><code>package org.andrea.myexample.HibernateOnSpring.dao;
  
  import java.util.List;
  
  import org.andrea.myexample.HibernateOnSpring.entity.Person;
  
  import org.hibernate.Criteria;
  import org.hibernate.HibernateException;
  import org.hibernate.Session;
  import org.hibernate.Transaction;
  import org.hibernate.SessionFactory;
  import org.hibernate.cfg.Configuration;
  import org.hibernate.service.ServiceRegistry;
  import org.hibernate.service.ServiceRegistryBuilder;
  import org.springframework.transaction.annotation.Transactional;
  
  public class PersonDAOImpl implements PersonDAO {
  
      // Factory per la creazione delle sessioni di Hibernate:
      private static SessionFactory sessionFactory;
  
      public void setSessionFactory(SessionFactory sessionFactory) {
          this.sessionFactory = sessionFactory;
      }
  
      // CREATE CRUD Operation:
      @Transactional(readOnly = false)
      public Integer addPerson(Person p) {
  
          System.out.println("Inside addPerson()");
  
          Session session = sessionFactory.openSession();
  
          Transaction tx = null;
          Integer personID = null;
  
          try {
              tx = session.beginTransaction();
  
              personID = (Integer) session.save(p);
              tx.commit();
          } catch (HibernateException e) {
              if (tx != null)
                  tx.rollback();
              e.printStackTrace();
          } finally {
              session.close();
          }
  
          return personID;
  
      }
  
      // READ CRUD Operation (legge un singolo record avente uno specifico id):
      public Person getById(int id) {
  
          System.out.println("Inside getById()");
  
          Session session = sessionFactory.openSession();
  
          Transaction tx = null;          
          Person retrievedPerson = null;  
  
          try {
              tx = session.beginTransaction();
              retrievedPerson = (Person) session.get(Person.class, id);
              tx.commit();
          }catch (HibernateException e) { 
              if (tx != null)                 
                  tx.rollback();          
              e.printStackTrace();
          } finally {                 
              session.close();
          }
  
          return retrievedPerson;
      }
  
      // READ CRUD Operation (recupera la lista di tutti i record nella tabella):
      @SuppressWarnings("unchecked")
      public List&lt;Person&gt; getPersonsList() {
  
          System.out.println("Inside getPersonsList()");
  
          Session session = sessionFactory.openSession();
          Transaction tx = null;
          List&lt;Person&gt; personList = null;
  
          try {
              tx = session.beginTransaction();
              Criteria criteria = session.createCriteria(Person.class);
              personList = criteria.list();
              System.out.println("personList: " + personList);
              tx.commit();
          }catch (HibernateException e) { 
              if (tx != null)                 
                  tx.rollback();          
              e.printStackTrace();
          } finally {
              session.close();
          }
          return personList;
      }
  
      // DELETE CRUD Operation (elimina un singolo record avente uno specifico id):
      public void delete(int id) {
  
          System.out.println("Inside delete()");
  
          Session session = sessionFactory.openSession();
          Transaction tx = null;
  
          try {
              tx = session.beginTransaction();
              Person personToDelete = getById(id);
              session.delete(personToDelete);
              tx.commit();
          }catch (HibernateException e) { 
              if (tx != null)                 
                  tx.rollback();          
              e.printStackTrace();
          } finally {
              session.close();
          }
  
      }
  
      @Transactional
      public void update(Person personToUpdate) {
  
          System.out.println("Inside update()");
  
          Session session = sessionFactory.openSession();
          Transaction tx = null;
  
          try {
              System.out.println("Insite update() method try");
              tx = session.beginTransaction();
              session.update(personToUpdate);
  
              tx.commit();
          }catch (HibernateException e) { 
              if (tx != null)                 
                  tx.rollback();          
              e.printStackTrace();
          } finally {
              session.close();
          }   
  
      }
  
  }
  </code></pre>
  
  <p>The problem is that if I use the <strong>3.2.1</strong> version for the <strong>spring-aop</strong> module instead of the <strong>3.2.0</strong> changing this dependency in this way:</p>
  
  <pre><code>    &lt;dependency&gt;   &lt;!-- Usata da Hibernate 4 per LocalSessionFactoryBean --&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
          &lt;version&gt;3.2.1.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>When I run Maven ---> Maven Install happen the compilation fail and return the following error message:</p>
  
  <pre><code>[ERROR] COMPILATION ERROR : 
  [INFO] -------------------------------------------------------------
  [ERROR] /home/andrea/Documents/ws/HibernateOnSpring/src/main/java/org/andrea/myexample/HibernateOnSpring/dao/PersonDAOImpl.java:[15,49] error: package org.springframework.transaction.annotation does not exist
  [ERROR] /home/andrea/Documents/ws/HibernateOnSpring/src/main/java/org/andrea/myexample/HibernateOnSpring/dao/PersonDAOImpl.java:[27,2] error: cannot find symbol
  [ERROR]  class PersonDAOImpl
  /home/andrea/Documents/ws/HibernateOnSpring/src/main/java/org/andrea/myexample/HibernateOnSpring/dao/PersonDAOImpl.java:[128,2] error: cannot find symbol
  [INFO] 3 errors 
  [INFO] -------------------------------------------------------------
  [INFO] ------------------------------------------------------------------------
  [INFO] BUILD FAILURE
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time: 3.288s
  [INFO] Finished at: Fri Mar 08 13:19:23 CET 2013
  [INFO] Final Memory: 12M/105M
  [INFO] ------------------------------------------------------------------------
  [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project HibernateOnSpring: Compilation failure: Compilation failure:
  [ERROR] /home/andrea/Documents/ws/HibernateOnSpring/src/main/java/org/andrea/myexample/HibernateOnSpring/dao/PersonDAOImpl.java:[15,49] error: package org.springframework.transaction.annotation does not exist
  [ERROR] /home/andrea/Documents/ws/HibernateOnSpring/src/main/java/org/andrea/myexample/HibernateOnSpring/dao/PersonDAOImpl.java:[27,2] error: cannot find symbol
  [ERROR] class PersonDAOImpl
  [ERROR] /home/andrea/Documents/ws/HibernateOnSpring/src/main/java/org/andrea/myexample/HibernateOnSpring/dao/PersonDAOImpl.java:[128,2] error: cannot find symbol
  [ERROR] -&gt; [Help 1]
  [ERROR] 
  [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
  [ERROR] Re-run Maven using the -X switch to enable full debug logging.
  [ERROR] 
  [ERROR] For more information about the errors and possible solutions, please read the following articles:
  [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
  </code></pre>
  
  <p>Andin the <strong>PersonDAOImpl</strong> happen that don't find the following imported class:</p>
  
  <pre><code>org.springframework.transaction.annotation.Transactional;
  </code></pre>
  
  <p>Why I have this problem if I try to use the 3.2.1 version of spring-orm module? How can I solve to use it?</p>