Monday, September 19, 2011

Identifying the state of hibernate objects practically

Emp instance=new Emp(); /* creating the transient object using the new operator which is not attached to database , which has to be saved in db usinh save or saveorupdate method of session object from sessionfactory */
instance.setEmpno(new Integer("111111"));
instance.setMgr(new Integer(6));
instance.setHiredate(new Date());
com.DeptHome deptHome=new com.DeptHome();
Dept dept2=deptHome.findById(40);/* userdefined method findById persist object which is attached with session need to update not to save*/

empHome.attachDirty(instance);/*user defined method conatins save method of session object to save instance to db*/

Emp emp=empHome.findById(7942);/* findById is user defined method to retrive the emp object using the emp id hence emp object is persist object attached to session which can be modified and save into database using the saveorupdate method of session object */


1 comment: