"Exception Prompt"
Transientobjectexception:object references an unsaved transient instance-save the transient instance before Flushing:co M.jspxcms.core.domain.scteam
"Online Reference"
"Reference II"
Title: Object references an unsaved transient instance-save the transient instance before flushing
Exception 1:not-Null property references a null or transient value
WORKAROUND: Set the "one" side of the "A-to-many" relationship to false Not-null
(Reference: http://www.thearcmind.com/confluence/pages/viewpage.action?pageId=212)
Exception 2:org.hibernate.transientobjectexception:object references an unsaved transient instance
Workaround: cascade= "Save-update,persist"
(Reference: http://www.laliluna.de/254.html)
Exception 3:org.hibernate.queryexception:could not resolve property
Workaround: "From category category where Category.userid =: userid" modified to "from category category Whereuserid =: userid" or "from Cate Gory category where Category.user.id =: UserID "
(Reference: http://www.laliluna.de/277.html)
Exception 4:could not initialize Proxy-the owning Session was closed
Workaround: Set lazy to False
(Reference: http://forum.springframework.org/showthread.PHP?t=27993)
Exception 2 I have encountered this problem in the application:
There are three tables: UserInfo deptmentinfo role
UserInfo and Deptmentinfo for many to one
UserInfo and role many to one
The following is the code to save the UserInfo object:
Deptmentinfo Dept = new Deptmentinfo ();
Dept.setdeptname (Deptname);
Role role = new role ();
Role.setrolename (RoleName);
UserInfo user = new UserInfo ();
User.setusername (UserName);
User.setusersex (Usersex);
User.setduty (duty);
User.setphone (phone);
User.setmobilenum (Mobilenum);
User.setemail (email);
USER.SETQQ (QQ);
USER.SETMSN (MSN);
User.setadress (adress);
User.setdeptmentinfo (dept);
User.setrole (role);
Dao.save (user);
Error during execution: Org.hibernate.TransientObjectException:object references an unsaved transient instance
and changed some parts of UserInfo.hbm.xml.
As follows:
<many-to-one name= "Role" class= "Com.oa.domain.Role"
cascade= "save-update,persist" fetch= "select" >
<column name= "role_id" precision= "$" scale= "0"/>
</many-to-one>
<many-to-one name= "Deptmentinfo"
class= "Com.oa.domain.DeptmentInfo" cascade= "Save-update,persist "
Fetch= "SELECT" >
<column name= "dept_id" precision= "$" scale= "0"/>
</many-to-one>
Add the red part above, OK, you can save it.
Object references an unsaved transient instance "exception"