title: Why is hibernate cascading by default when I don't have any CascadeTypes set
body: <p>I'm running into the following exception when I'm trying to persist new <code>swipe</code> objects:
  <code>javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: org.munch.database.models.bunch.Munch</code></p>
  <p>Here is the code I am executing:</p>
  <pre><code>databaseExecutor.executeAndRollbackOnFailure { entityManager -&gt;
          munch.swipes.forEach {
              if (it.swipeIdKey.munchId != null) {
                  entityManager.persist(it)
              } else if (it.updated) {
                  entityManager.merge(it)
              }
          }
          entityManager.transaction.commit()
      }
  </code></pre>
  <p>I've also pasted my entities below for reference.
  When <code>entityManager.persist(it)</code> is called, the above error is thrown. It is for some reason trying to persist the <code>OneToMany</code> side of the entity as well which will not work. I've made sure that the <code>CascadeTypes</code> arrays are empty for both so by my understanding only the <code>Swipe</code> that I call <code>entityManager.persist()</code> on should be written to the db.</p>
  <p>If I replace <code>persist</code> with <code>merge</code> the operation succeeds but the merge causes hibernate to generate an additional <code>select</code> for the <code>Munch</code> and also a <code>select</code> for the <code>Swipe</code> which are unnecessary operations. The merge does not however seem to cascade the update operation to the <code>Munch</code> it only does the 2 select statements and 1 insert.</p>
  <p>To recap:
  Hibernate seems to be cascading the <code>Persist</code> operation when it shouldn't. A solution is to use <code>merge</code> instead but using <code>persist</code> should result only in <code>1 insert</code> where as <code>merge</code> results in <code>2 selects + 1 insert</code></p>
  <p>I'm out of ideas other than executing native queries to insert/update but I'd like to avoid that if possible.</p>
  <p>Here are my entities:</p>
  <p><code>Munch</code></p>
  <pre><code>
  @Entity
  @TypeDefs(
      TypeDef(
          name = &quot;list-array&quot;,
          typeClass = ListArrayType::class
      )
  )
  data class Munch(
      @Column
      val name: String,
      @OneToMany(
          fetch = FetchType.LAZY,
          mappedBy = &quot;munch&quot;,
      )
      val swipes: MutableList&lt;Swipe&gt; = mutableListOf(),
  ) {
      @Id
      @GenericGenerator(name = &quot;generator&quot;, strategy = &quot;uuid&quot;)
      @GeneratedValue(generator = &quot;generator&quot;)
      lateinit var munchId: String
  
      fun addSwipe(swipe: Swipe) {
          swipes.add(swipe)
          swipe.munch = this
      }
  }
  </code></pre>
  <p><code>Swipe</code></p>
  <pre><code>@Entity
  data class Swipe(
      @EmbeddedId
      val swipeIdKey: SwipeIdKey,
      @Column(nullable = true)
      val liked: Boolean,
  ) : Serializable {
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = &quot;munchId&quot;)
      @MapsId(&quot;munchId&quot;)
      lateinit var munch: Munch
  
      @Transient
      var updated = false
  </code></pre>
  <p><code>SwipeIdKey</code></p>
  <pre><code>@Embeddable
  class SwipeIdKey : Serializable {
  
      @Column(nullable = false)
      lateinit var restaurantId: String
  
      @Column(nullable = true)
      lateinit var userId: String
  
      @Column(nullable = true)
      var munchId: String? = null
  }
  </code></pre>