title: CrudRepository's save method returns a bean even though it was not created
body: <p>I am using Spring (3.11) data/ repositories together with JPA (2.0)/ Hibernate (3.5.6) and I have an issue to do with the CrudRepository's save method.</p>
  
  <p>The global service I have is as follows:</p>
  
  <pre><code>@Override
  @Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
  public MyBean createMyBean(MyBean myBean) {
  
  
      // 1)
      // myBean does not have PK, it will be generated via sequence
      MyBean myBean = myBeanRepository.save(myBean);
  
      // 2)
      // sends event to queue
      syncEventProducer.sendSyncEvent(....);
  
      return myBean;
  }
  </code></pre>
  
  <p>My problem is simple: I am inserting on purpose a certain myBean that does not satisfy the table requirements (typically I am setting as null a column which was created as not null in the DB) then an exception (e.g. DataIntegrityViolationException) is being produced internally in the call 1) but 2) still gets executed. Why is that?</p>
  
  <p>MyBeanRepository is like this: </p>
  
  <pre><code>public interface MyBeanRepository extends CrudRepository&lt;MyBean, Integer&gt; {
  
  }
  </code></pre>
  
  <p>Digging a little bit in the code I have seen that the SimpleJpaRepository related to my repository returns indeed my bean with a new PK even though that should not have happened.</p>
  
  <p>Of course at the end the whole transaction is rollbacked but still I do not get to understand why myBeanRepository.save(myBean) "swallows" the exception up and returns instead a new bean with a new PK.</p>
  
  <p>Thanks,</p>
  
  <p>Javi</p>