title: Hibernate TransientPropertyValueException When saving data
body: <p>I am trying to insert data to the DB using hibernate . Here is how I going perform that action </p>
  
  <pre><code>    session.beginTransaction();
      pojo.StuDetails stu = new StuDetails();
      stu.setFName(f_name);
      stu.setLName(l_name);
      stu.setSex(sex);
      stu.setDob(dob);
  
      pojo.Subject sub = new Subject(subject, day, time);
      pojo.SubjectHasStuDetails shs = new SubjectHasStuDetails(stu, sub);
  
      session.save(shs);
      session.getTransaction().commit();  
  </code></pre>
  
  <p>But It gives me an error saying </p>
  
  <blockquote>
    <p>Exception in thread "main"
    org.hibernate.TransientPropertyValueException: Not-null property
    references a transient value - transient instance must be saved before
    current operation</p>
  </blockquote>
  
  <p>Here is my student details entity</p>
  
  <pre><code> public class StuDetails  implements java.io.Serializable {
  
  
   private Integer id;
   private String FName;
   private String LName;
   private String sex;
   private String dob;
   private Set subjectHasStuDetailses = new HashSet();
   ...
   //constructors and getters, setters
  </code></pre>
  
  <p>My StudentDetails hbm.xml</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
      &lt;class name="pojo.StuDetails" table="stu_details" catalog="laravel_test" optimistic-lock="version"&gt;
          &lt;id name="id" type="java.lang.Integer"&gt;
              &lt;column name="id" /&gt;
              &lt;generator class="identity" /&gt;
          &lt;/id&gt;
          &lt;property name="FName" type="string"&gt;
              &lt;column name="f_name" length="45" not-null="true" /&gt;
          &lt;/property&gt;
          &lt;property name="LName" type="string"&gt;
              &lt;column name="l_name" length="45" not-null="true" /&gt;
          &lt;/property&gt;
          &lt;property name="sex" type="string"&gt;
              &lt;column name="sex" length="45" not-null="true" /&gt;
          &lt;/property&gt;
          &lt;property name="dob" type="string"&gt;
              &lt;column name="dob" length="45" not-null="true" /&gt;
          &lt;/property&gt;
          &lt;set name="subjectHasStuDetailses" table="subject_has_stu_details" inverse="true" lazy="true" fetch="select"&gt;
              &lt;key&gt;
                  &lt;column name="stu_details_id" not-null="true" /&gt;
              &lt;/key&gt;
              &lt;one-to-many class="pojo.SubjectHasStuDetails" /&gt;
          &lt;/set&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>My Subject Entity looks like  </p>
  
  <pre><code> public class Subject  implements java.io.Serializable {
  
  
   private Integer id;
   private String subName;
   private String day;
   private String time;
   private Set subjectHasStuDetailses = new HashSet();
  
   ...
   //constructors and getters, setters
  </code></pre>
  
  <p>Subject.hbm.xml</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
      &lt;class name="pojo.Subject" table="subject" catalog="laravel_test" optimistic-lock="version"&gt;
          &lt;id name="id" type="java.lang.Integer"&gt;
              &lt;column name="id" /&gt;
              &lt;generator class="identity" /&gt;
          &lt;/id&gt;
          &lt;property name="subName" type="string"&gt;
              &lt;column name="sub_name" length="45" not-null="true" /&gt;
          &lt;/property&gt;
          &lt;property name="day" type="string"&gt;
              &lt;column name="day" length="45" not-null="true" /&gt;
          &lt;/property&gt;
          &lt;property name="time" type="string"&gt;
              &lt;column name="time" length="45" not-null="true" /&gt;
          &lt;/property&gt;
          &lt;set name="subjectHasStuDetailses" table="subject_has_stu_details" inverse="true" lazy="true" fetch="select"&gt;
              &lt;key&gt;
                  &lt;column name="subject_id" not-null="true" /&gt;
              &lt;/key&gt;
              &lt;one-to-many class="pojo.SubjectHasStuDetails" /&gt;
          &lt;/set&gt;
  
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>Here is the SubjetcHasStuDetails Entity</p>
  
  <pre><code> public class SubjectHasStuDetails  implements java.io.Serializable {
  
  
   private Integer id;
   private StuDetails stuDetails;
   private Subject subject;
   ...
   //constructors and getters, setters
  </code></pre>
  
  <p>SubjectHasStuDetials.hbm.xml</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
      &lt;class name="pojo.SubjectHasStuDetails" table="subject_has_stu_details" 
             catalog="laravel_test" optimistic-lock="version"&gt;
          &lt;id name="id" type="java.lang.Integer"&gt;
              &lt;column name="id" /&gt;
              &lt;generator class="identity" /&gt;
          &lt;/id&gt;
          &lt;many-to-one name="stuDetails" class="pojo.StuDetails" fetch="select"&gt;
              &lt;column name="stu_details_id" not-null="true" /&gt;
          &lt;/many-to-one&gt;
          &lt;many-to-one name="subject" class="pojo.Subject" fetch="select" &gt;
              &lt;column name="subject_id" not-null="true" /&gt;
          &lt;/many-to-one&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>Can someone help me on this error please ... Thanks..</p>