title: Is it possible to cascade none in hibernate spring
body: <p>I am new to Hibernate and Spring,</p>
  <p>I have an object <code>Course</code> and object <code>User</code>.</p>
  <p>So, the logic is the admin can create a course using an existing user and
  the existing user will already have an existing role.</p>
  <p>My repository class for the <code>Course</code> object extends <code>CrudRepository</code>.
  To save the course object, I use</p>
  <pre class="lang-java prettyprint-override"><code>courseRepository.save(course);
  </code></pre>
  <p>But I have an issue with the following error:</p>
  <pre><code>org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing : com.example.project.model.Course.user -&gt; com.example.project.model.User
  </code></pre>
  <p>I am not sure how to not save the <code>User</code> and <code>Role</code> object which already exists in the database. I tried to use <code>CascadeType.None</code> but I can't find the import/ dependency. Currently, it keeps forcing me to save into the database the user and role object which causes duplicate data.</p>
  <p>Course class :</p>
  <pre class="lang-java prettyprint-override"><code>@Entity
  public class Course {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private long course_id;
      private String course_name;
      private String course_desc;
  
      @ManyToOne(cascade = {})
      @JoinColumn(name=&quot;teacher_id&quot;, referencedColumnName = &quot;user_id&quot;)
      private User user;
  
      //setter &amp; getter
  }
  </code></pre>
  <p>User class:</p>
  <pre class="lang-java prettyprint-override"><code>@Entity
  public class User {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private long user_id;
      private String username;
      private String password;
      private String firstname;
      private String lastname;
      private String email;
      private String identificationNumber;
      
      @ManyToOne(cascade = {})
      @JoinColumn(name=&quot;role_id&quot;)
      private Role role;
  }
  </code></pre>
  <p>Role class:</p>
  <pre class="lang-java prettyprint-override"><code>@Entity
  public class Role {
      
      @Id
      private long role_id;
      private String role_name;
      private String role_desc;
  }
  </code></pre>