Hibernate TransientPropertyValueException When saving data

后端 未结 1 1883
没有蜡笔的小新
没有蜡笔的小新 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 :

    
                
            
    
                
            
    

    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)
提交回复
热议问题