Hibernate TransientPropertyValueException When saving data

后端 未结 1 1884
没有蜡笔的小新
没有蜡笔的小新 2021-01-19 05:58

I am trying to insert data to the DB using hibernate . Here is how I going perform that action

    session.beginTransaction();
    pojo.StuDetails stu = new         


        
相关标签:
1条回答
  • 2021-01-19 06:28

    In your SubjectHasStuDetials.hbm.xml make these changes :

    <many-to-one name="stuDetails" class="pojo.StuDetails" fetch="select" cascade="all">
                <column name="stu_details_id" not-null="true" />
            </many-to-one>
    <many-to-one name="subject" class="pojo.Subject" fetch="select" cascade="all" >
                <column name="subject_id" not-null="true" />
            </many-to-one>
    

    Add cascade="all" attribute to both stuDetails and subject many-to-one tags.

    • Cascade attribute is mandatory, when ever we apply relationship between objects, cascade attribute transfers operations done on one object onto its related child objects
    • If we write cascade = “all” then changes at parent class object will be effected to child class object too, if we write cascade = “all” then all operations like insert, delete, update at parent object will be effected to child object also.
    • Example: if we apply insert(or update or delete) operation on parent class object, then child class objects will also be stored into the database.
    0 讨论(0)
提交回复
热议问题