title: Spring Jpa @Transactional not working
body: <p>I am trying to achieve transaction roll back if one or more queries fail. so i annotated <code>@Transactional</code> on my service implementation class. I knowingly sent wrong data type amountpaid1 (String in this case, Double is correct data type).</p>
  
  <p>But now, my first update query plus insertion on challan completes successfully.<br/> Second query i.e query1 fails to update as it receives wrong data type so i expect the whole transaction to roll back. </p>
  
  <p><strong>Repository</strong></p>
  
  <pre><code>@Repository
  public class UpdatePaymentImpl implements UpdatePayment {
  
  
  @PersistenceContext
  EntityManager em;
  
  public PaymentResponse getFcgoApiResponse(FcgoUpdateParam updateParam){
      PaymentResponse paymentResponse = new PaymentResponse();
      try {
          final String uri = "http://a.b.c.d:xxxx/FcgoApi/api/savePayment";
          RestTemplate restTemplate = new RestTemplate();
          paymentResponse = restTemplate.postForObject(uri, updateParam, 
          PaymentResponse.class);
              if (paymentResponse.getVoucherNo() != null) {
                  int status = updatePayment(updateParam, 
                  paymentResponse.getVoucherNo());
                  if (status == 0) {
                      vc.setVoucherNo(paymentResponse.getVoucherNo());
                  }
              }
      }catch (Exception ex){
          ex.printStackTrace();
          logger.info(ex.getMessage());
      }
      return paymentResponse;
  
  }
  
  
      @Transactional
      public int updatePayment(FcgoUpdateParam updateParam, String voucherno){
  
          try{
              String amountPaid1 = updateParam.getAmountPaid();
              Double amountPaid=Double.parseDouble(updateParam.getAmountPaid());
              String masterId= updateParam.getMasterId();
              String advCode=updateParam.getAdvCode();
              long uuid = getUniqueID();
              logger.info("generated uuid "+uuid);
              DateFormat dateFormat =new SimpleDateFormat("dd-MMM-yy h.mm.ss.000000000 a");
              SimpleDateFormat dms = new SimpleDateFormat("dd-MM-yyyy");
              String cdate = updateParam.getChallanDate();
              Date ddate= dms.parse(cdate);
              String challandate = dateFormat.format(ddate);
              String office = updateParam.getOffice();
              String username = updateParam.getUsername();
              Long id = getIdOnChallanTable()+1L;
  
              String challanid = String.valueOf(uuid);
              ChallanEntity challanEntity = new ChallanEntity();
              challanEntity.setAdvtcode(updateParam.getAdvCode());
              challanEntity.setAmount(amountPaid);
              challanEntity.setName(updateParam.getName());
              challanEntity.setOffice(office);
              challanEntity.setUsername(username);
              challanEntity.setStatus(updateParam.getStatus());
              challanEntity.setChallandate(challandate);
              challanEntity.setChallanid(uuid);
              challanEntity.setChallantime("null");
              challanEntity.setVoucherno(voucher no);
              Query query= em.createQuery("update 
              CandidateappearagainstadvtcodeEntity cd set 
       cd.paymentstatus='Completed',cd.amountpaid=:depoFee,cd.challanid=:challanid
               where cd.studentmasterid=:masterid and cd.advertisementcode=:advCode");
              logger.info("update parameter advt code: "+updateParam.getAdvCode());
              query.setParameter("depoFee",updateParam.getAmountPaid());
              query.setParameter("challanid",challanid);
              query.setParameter("masterid",masterId);
              query.setParameter("advCode",advCode)
              .executeUpdate();
              Query query1 =em.createQuery(" update CandidateappeartoadvtnumberEntity 
              cnd set cnd.paymentstatus='Completed', cnd.depositedfee=:depofee where
              cnd.studentmasterid=:masterid and cnd.advertisementcode=:advcode");
              String masterId1= updateParam.getMasterId();
              String advCode1=updateParam.getAdvCode();
  
              query1.setParameter("depofee",amountPaid1);
              query1.setParameter("masterid",masterId1);
              query1.setParameter("advcode",advCode1)
              .executeUpdate();
  
              em.persist(challanEntity);
              em.flush();
          }
          catch (Exception e){
              logger.info("update error " +e);
              logger.info(e.getMessage());
              return 0;
  
          }
          return 1 ;
      }
  
      }
  </code></pre>
  
  <p><strong>Service Class</strong></p>
  
  <pre><code>    @Service
      public class UpdatePaymentServiceImpl implements UpdatePaymentService {
  
      @Autowired
      UpdatePayment updatePayment;
  
      @Transactional
      public PaymentResponse getFcgoApiResponse(FcgoUpdateParam updateParam) {
          return updatePayment.getFcgoApiResponse(updateParam);
      }
  
      }
  </code></pre>
  
  <p><strong>ApplicationContext.xml</strong></p>
  
  <pre><code>    &lt;bean id="entityManagerFactory" class="org.springframework.
      orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;property name="packagesToScan" value="com.psc" /&gt;
      &lt;property name="jpaVendorAdapter"&gt;
          &lt;bean class="org.springframework.orm.jpa.vendor.
              HibernateJpaVendorAdapter" /&gt;
      &lt;/property&gt;
      &lt;property name="jpaProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt;
              &lt;prop key="hibernate.dialect"&gt;
                  org.hibernate.dialect.Oracle10gDialect&lt;/prop&gt;
              &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
     &lt;/bean&gt;
     &lt;bean id="transactionManager" 
      class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
      &lt;property name="entityManagerFactory" 
          ref="entityManagerFactory" /&gt;
      &lt;/bean&gt;
  </code></pre>