Hibernate TransientPropertyValueException при сохранении данных

Я пытаюсь вставить данные в БД с помощью спящего режима. Вот как я собираюсь выполнить это действие

    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();  

Но это дает мне ошибку, говоря

Исключение в потоке "main" org.hibernate.TransientPropertyValueException: свойство Not-null ссылается на временное значение - временный экземпляр должен быть сохранен перед текущей операцией

Вот моя сущность детали студента

 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

Мой StudentDetails hbm.xml

<hibernate-mapping>
    <class name="pojo.StuDetails" table="stu_details" catalog="laravel_test" optimistic-lock="version">
        <id name="id" type="java.lang.Integer">
            <column name="id" />
            <generator class="identity" />
        </id>
        <property name="FName" type="string">
            <column name="f_name" length="45" not-null="true" />
        </property>
        <property name="LName" type="string">
            <column name="l_name" length="45" not-null="true" />
        </property>
        <property name="sex" type="string">
            <column name="sex" length="45" not-null="true" />
        </property>
        <property name="dob" type="string">
            <column name="dob" length="45" not-null="true" />
        </property>
        <set name="subjectHasStuDetailses" table="subject_has_stu_details" inverse="true" lazy="true" fetch="select">
            <key>
                <column name="stu_details_id" not-null="true" />
            </key>
            <one-to-many class="pojo.SubjectHasStuDetails" />
        </set>
    </class>
</hibernate-mapping>

Моя тема выглядит так

 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

Subject.hbm.xml

<hibernate-mapping>
    <class name="pojo.Subject" table="subject" catalog="laravel_test" optimistic-lock="version">
        <id name="id" type="java.lang.Integer">
            <column name="id" />
            <generator class="identity" />
        </id>
        <property name="subName" type="string">
            <column name="sub_name" length="45" not-null="true" />
        </property>
        <property name="day" type="string">
            <column name="day" length="45" not-null="true" />
        </property>
        <property name="time" type="string">
            <column name="time" length="45" not-null="true" />
        </property>
        <set name="subjectHasStuDetailses" table="subject_has_stu_details" inverse="true" lazy="true" fetch="select">
            <key>
                <column name="subject_id" not-null="true" />
            </key>
            <one-to-many class="pojo.SubjectHasStuDetails" />
        </set>

    </class>
</hibernate-mapping>

Вот объект SubjetcHasStuDetails

 public class SubjectHasStuDetails  implements java.io.Serializable {


 private Integer id;
 private StuDetails stuDetails;
 private Subject subject;
 ...
 //constructors and getters, setters

SubjectHasStuDetials.hbm.xml

<hibernate-mapping>
    <class name="pojo.SubjectHasStuDetails" table="subject_has_stu_details" 
           catalog="laravel_test" optimistic-lock="version">
        <id name="id" type="java.lang.Integer">
            <column name="id" />
            <generator class="identity" />
        </id>
        <many-to-one name="stuDetails" class="pojo.StuDetails" fetch="select">
            <column name="stu_details_id" not-null="true" />
        </many-to-one>
        <many-to-one name="subject" class="pojo.Subject" fetch="select" >
            <column name="subject_id" not-null="true" />
        </many-to-one>
    </class>
</hibernate-mapping>

Может кто-нибудь помочь мне в этой ошибке, пожалуйста ... Спасибо ..

Ответы на вопрос(1)

Ваш ответ на вопрос