首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

一对多/多对1 cascade属性 inverse属性 随记

2012-08-26 
一对多/多对一 cascade属性 inverse属性 随记基本配置操作:http://yafei.iteye.com/blog/799999inverse属

一对多/多对一 cascade属性 inverse属性 随记
基本配置操作:http://yafei.iteye.com/blog/799999
inverse属性:http://www.iteye.com/topic/2633
inverse属性及hibernate其它知识(易理解):http://www.javaworld.com.tw/confluence/pages/viewpage.action?pageId=3479

Session s=null;Transaction tx=null;try{s=HibernateSessionFactory.getSession();tx=s.beginTransaction();    //hibernate的事务默认是关闭的,我们必须把他打开。Parent parent = new Parent();;                Child child = new Child();;                Child child2 = new Child();;                List list = new ArrayList();;                list.add(child);;                list.add(child2);;                parent.setChild(list);;                s.save(parent);;                s.flush();;                System.out.println("dddddddddddddddddddddddddddddddddddddddddddddddddddddd"); ;                Child child3 = new Child();;              child3.setParent(parent);;  //            child.setParent(parent);//            child2.setParent(parent);            s.save(child3);;  //            s.save(child);;//            s.save(child2);;            System.out.println("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"); ;    tx.commit();}catch(HibernateException e){if(tx!=null){tx.rollback();}throw e;}finally{if(s!=null){s.close();}}


去掉parent里的[color=red]inverse="true" 属性
Hibernate: select SEQ_PAERENTID.nextval from dual
Hibernate: select SEQ_ID.nextval from dual
Hibernate: select SEQ_ID.nextval from dual
Hibernate: insert into PARENT (PARENTID) values (?)
Hibernate: insert into CHILD (PARENTID, ID) values (?, ?)
Hibernate: insert into CHILD (PARENTID, ID) values (?, ?)
Hibernate: update CHILD set PARENTID=? where ID=?
Hibernate: update CHILD set PARENTID=? where ID=?
dddddddddddddddddddddddddddddddddddddddddddddddddddddd
Hibernate: select SEQ_ID.nextval from dual
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
Hibernate: insert into CHILD (PARENTID, ID) values (?, ?)
ID          PARENTID   
----------- -----------   
         74           19   
         75           19  
         76           19


不去掉parent里的[color=red]inverse="true" 属性
Hibernate: select SEQ_PAERENTID.nextval from dual
Hibernate: select SEQ_ID.nextval from dual
Hibernate: select SEQ_ID.nextval from dual
Hibernate: insert into PARENT (PARENTID) values (?)
Hibernate: insert into CHILD (PARENTID, ID) values (?, ?)
Hibernate: insert into CHILD (PARENTID, ID) values (?, ?)
dddddddddddddddddddddddddddddddddddddddddddddddddddddd
Hibernate: select SEQ_ID.nextval from dual
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
Hibernate: insert into CHILD (PARENTID, ID) values (?, ?)

ID          PARENTID   
----------- -----------   
         74           -   
         75           -  
         76           19

热点排行