title: Hibernate insert in catch block
body: <p>I am using Jax-Rs web service and hibernate. I am doing an insert, and if that insert fails, I should catch the exception and write a log in the database. Here is the code below</p>
  
  <pre><code>   @PersistenceContext(unitName = "primary")
     private EntityManager em;
  
     @GET
     @Produces("application/json")
     @Path("/siminsert")      
     public String testSimInsert()
     {
         try
         {
            Query query = em.createNativeQuery("insert into sim(iccid, imsi, msisdn, state) values ('890000000000010000512223334', '001010000100004', '50100005', 'A')");
            query.executeUpdate();
         }
         catch(Exception ex)
         {           
             Query query1 = em.createNativeQuery("insert into notifications(message) values ('An error occured')");
             query1.executeUpdate();
  
         }
  
        return "OK";
        } 
  </code></pre>
  
  <p>With this code, the first insert will fail since we are inserting more than allowed characters in the iccid field. I want to be able to log that error by doing an insert in the notifications table as shown in the code but i get the error:</p>
  
  <pre><code>  javax.persistence.TransactionRequiredException: Executing an update/delete query
  </code></pre>
  
  <p>Any ideas on what can be done?</p>