title: Synchronized deleting from two tables by expired date
body: <p>I have three tables in my database:</p>
  
  <p>First one of <code>COMPANY</code> that includes <code>id</code>, <code>name</code> and <code>email</code>.<br>
  Second - <code>COUPON</code> that includes id<code>,</code> <code>title</code>, <code>dates</code>, <code>price</code> etc...<br>
  Third - join table <code>COMPANY_COUPON</code> that includes <code>id</code> of the companies and <code>id</code> of the coupons which they own.</p>
  
  <p>In java, I have a method that deletes expired coupons using: </p>
  
  <pre><code>DELETE FROM COUPON WHERE END_DATE &lt; CURRENT_DATE
  </code></pre>
  
  <p>But after deleting expired coupons, I still have their <code>id</code> in <code>COMPANY_ COUPON</code> join table, how can I solve this?</p>
  
  <pre><code>@Override
  public void removeExpiredCoupons() throws CouponSystemException {
  
      String delete = "DELETE FROM COUPON WHERE END_DATE &lt; CURRENT_DATE";
  
      Connection connection = pool.getConnection();
  
      try (PreparedStatement pstmt = connection.prepareStatement(delete)) {
          pstmt.executeUpdate();
  
          // This line can be removed
          System.out.println("All expired coupos are removed.");
      } catch (SQLException e) {
          throw new CouponSystemException("Removing expired coupons is failed. ", e);
      } finally {
          pool.returnConnection(connection);
      }
  }
  </code></pre>