title: Spring Data JPA strange behavior
body: <p>I'm new to JPA and Hibernate and came across strange behavior. Consider the code below.</p>
  
  <p><code>License</code> entity:</p>
  
  <pre><code>@Entity
  @Data
  public class License {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private long id;
      @Enumerated(EnumType.STRING)
      private LicenseType type;
      @Column(unique = true)
      private String activationKey;
      @OneToMany(mappedBy = "id", cascade = CascadeType.REMOVE)
      private List&lt;Payment&gt; payments = new ArrayList&lt;&gt;();
      private long productId;
      private String productName;
      private long term;
      private long creationTimestamp;
      private boolean active;
  }
  </code></pre>
  
  <p><code>LicenceType</code> enum:</p>
  
  <pre><code>public enum LicenseType {
      NAMED
  }
  </code></pre>
  
  <p><code>Payment</code> entity:</p>
  
  <pre><code>@Entity
  @Data
  public class Payment {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private long id;
      @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.REFRESH})
      private License license;
      private BigDecimal sum;
  }
  </code></pre>
  
  <p><code>LicenceRepository</code>:</p>
  
  <pre><code>@Repository
  public interface LicenseRepository extends CrudRepository&lt;License, Long&gt; {
  
  }
  </code></pre>
  
  <p><code>PaymentRepository</code>:</p>
  
  <pre><code>@Repository
  public interface PaymentRepository extends CrudRepository&lt;Payment, Long&gt; {
  
  }
  </code></pre>
  
  <p>Bootstrap class:</p>
  
  <pre><code>@SpringBootApplication
  public class LsPocApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(LsPocApplication.class, args);
      }
  
      @Bean
      public CommandLineRunner demo(LicenseRepository licenseRepository, PaymentRepository paymentRepository) {
          return (args) -&gt; {
  
              License license = new License();
              license.setActivationKey(UUID.randomUUID().toString());
  
              Payment payment = new Payment();
              payment.setSum(BigDecimal.valueOf(new Random().nextDouble()));
              payment.setLicense(license);
  
              paymentRepository.save(payment);
  
              // licenseRepository.delete(license); // This does nothing
              // licenseRepository.delete(license.getId()); // This deletes both licence and associated payment(s)
          };
      }
  }
  </code></pre>
  
  <p>So the question is why the <code>licenseRepository.delete(license.getId())</code> works as intended, but <code>licenseRepository.delete(license)</code> does nothing? I assumed, they are logically equivalent. Or I'm wrong?</p>
  
  <p>Please advise.</p>
  
  <p>Thanks in advance!</p>