title: Spring Transaction if the this duplicated key gives the exception, but it does not do the Rollback (Updated code to detect better the error)
body: <p>In the Transaction if there is an exception for duplicate of key, that happens in the second persist, , the first one it persists and does not do the Rollback, and this one remains recorded in the database. <strong>(Updated question with more code to detect better the error)</strong></p>
  
  <pre><code>      public interface TemperaturesDao {
          @Transactional (rollbackFor=Throwable.class)
      // @Transactional (rollbackFor=Exception.class) // changed
          void save(JavaTemperatures jT);
      }
  
      @Repository
      public class TemperaturesDaoImp implements TemperaturesDao{
          @Autowired
          private SessionFactory sf;
          @Transactional (rollbackFor=Throwable.class)
          // @Transactional (rollbackFor=Exception.class) // changed
          public void save(JavaTemperatures jT) {
              Session session = sf.getCurrentSession();
              session.save(jT);
          }
      }
  
  
      public interface TemperaturesService {
          @Transactional (rollbackFor=Throwable.class)
      // @Transactional (rollbackFor=Exception.class) // changed
          void saveService();
      }
  
      @Service("temperaturesServiceImp")
      public class TemperaturesServiceImp implements TemperaturesService{
          @Autowired
          TemperaturesDao tempeDao;
  
          @Transactional (rollbackFor=Throwable.class)
      // @Transactional (rollbackFor=Exception.class) // changed
          public void saveService() {
              JavaTemperatures jT = new JavaTemperatures();
              jT.setKey("key2");
              tempeDao.save(jT); // This is registered in the database at the end of the veService
  
              jT = new JavaTemperatures();
              jT.setKey("key1"); // This key exists in the database
              tempeDao.save(jT); // This record gives exception at the end of the saveService
          }
      }
  
  
      public class BaseBeanImp implements Serializable{
          ...
      }
  
      @Controller
      @Scope("session")
      public class ComparaBean extends BaseBeanImp implements Serializable {
          private static final long serialVersionUID = 1L;
          @Autowired
          private TemperaturesService tempeService;
  
          public String doSave() {
              tempeService.saveService() ;
              return null;
          }
      }
  
      **index.xhtml**
      &lt;h:commandButton value="Save" action="#{comparaBean.doSave}" /&gt;
  </code></pre>
  
  <p><strong>applicationContext.xml</strong></p>
  
  <pre><code>&lt;beans xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd" xmlns="http://www.springframework.org/schema/beans" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; 
  
  &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" &gt;
  &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" &gt; &lt;/property&gt;
  &lt;property name="url" value="jdbc:mysql://redhada.org:3306/db" &gt; &lt;/property&gt;
  &lt;property name="username" value="username" &gt; &lt;/property&gt;
  &lt;property name="password" value="password" &gt;&lt;/property&gt;
  &lt;property name="testOnBorrow" value="true" &gt; &lt;/property&gt;
  &lt;property name="validationQuery" value="SELECT 1" &gt;&lt;/property&gt;
  &lt;property name="timeBetweenEvictionRunsMillis" value="1200000" &gt;&lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" &gt;
  &lt;property name="dataSource" ref="dataSource" &gt; &lt;/property&gt;
  &lt;property name="annotatedClasses" &gt;
      &lt;list&gt;
      &lt;value&gt;com.redhada.model.JavaTemperatures&lt;/value&gt;
      &lt;/list&gt;
  &lt;/property&gt;
  &lt;property name="hibernateProperties"&gt;
  &lt;props&gt;&lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;&lt;/property&gt;
  &lt;/bean&gt;
  &lt;context:annotation-config&gt;&lt;/context:annotation-config&gt;
  &lt;context:component-scan base-package="com.redhada"&gt;&lt;/context:component-scan&gt;
  &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  &lt;bean id="transactionManager"
   class="org.springframework.orm.hibernate3.HibernateTransactionManager" &gt;
  &lt;property name="sessionFactory" ref="sessionFactory" &gt; &lt;/property&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>Console:</strong></p>
  
  <pre><code>263194 [http-8080-Processor23] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 1062, SQLState: 23000
  263194 [http-8080-Processor23] ERROR org.hibernate.util.JDBCExceptionReporter - Duplicate entry 'clave31' for key 1
  263195 [http-8080-Processor23] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
  ...
  Caused by: java.sql.BatchUpdateException: Duplicate entry 'key1' for key 1
  ...
  Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Duplicate entry 'key1' for key 1
  ...
  </code></pre>
  
  <p><strong>But it save the record</strong></p>
  
  <p><strong>Why does persist if the second tempeDao.save gives the exception?</strong></p>
  
  <p><strong>Why does not do the Rollback?</strong></p>