posts - 64,  comments - 9,  trackbacks - 0

          配置文件:
          班級:
          <hibernate-mapping>
           
           <class name="bjca.testHibernate.entity.impl.ClassInfo" table="t_class">
             <id name="claId" type="java.lang.Integer">
                      <column name="claId" />
                      <generator class="native" />
                  </id>
            <property name="claName" type="java.lang.String">
                      <column name="claName" length="50" not-null="true" />
                  </property>
                
            <set name="students" inverse="true">
             <key column="classId"></key>
             <one-to-many class="bjca.testHibernate.entity.impl.StudentInfo"/>
            </set>
            
               </class>
          </hibernate-mapping>

          學生
          <hibernate-mapping>
           
           <class name="bjca.testHibernate.entity.impl.StudentInfo" table="t_student">
             <id name="stuId" type="java.lang.Integer">
                      <column name="id" />          
                       <generator class="native" />
                  </id>
            <property name="stuName" type="java.lang.String">
                      <column name="stuName" length="50" not-null="true" />
                  </property>
                 
                  <many-to-one name="classes" column="classId"

          class="bjca.testHibernate.entity.impl.ClassInfo" cascade="all"/>
           </class>
          </hibernate-mapping>


          插入一個班級:
          log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
          log4j:WARN Please initialize the log4j system properly.
          Hibernate: select hibernate_sequence.nextval from dual
          Hibernate: insert into t_class (claName, claId) values (?, ?)
          11111


          插入一個學生:
          log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
          log4j:WARN Please initialize the log4j system properly.
          Hibernate: select hibernate_sequence.nextval from dual
          Hibernate: insert into t_student (stuName, classId, id) values (?, ?, ?)
          11111


          修改一條學生信息:
          11111
          log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
          log4j:WARN Please initialize the log4j system properly.
          Hibernate: select studentinf0_.id as id0_, studentinf0_.stuName as stuName0_,

          studentinf0_.classId as classId0_ from t_student studentinf0_ where studentinf0_.id=10
          Hibernate: select classinfo0_.claId as claId1_, classinfo0_.claName as claName1_ from t_class

          classinfo0_ where classinfo0_.claId=11
          Hibernate: select studentinf0_.id as id0_0_, studentinf0_.stuName as stuName0_0_,

          studentinf0_.classId as classId0_0_ from t_student studentinf0_ where studentinf0_.id=?
          Hibernate: update t_student set stuName=?, classId=? where id=?
          Hibernate: update t_class set claName=? where claId=?

          修改一條班級信息:
          11111
          log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
          log4j:WARN Please initialize the log4j system properly.
          Hibernate: select classinfo0_.claId as claId1_, classinfo0_.claName as claName1_ from t_class

          classinfo0_ where classinfo0_.claId=11
          Hibernate: update t_class set claName='大象二班' where claId=11

          班級信息級聯 all
          11111
          log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
          log4j:WARN Please initialize the log4j system properly.
          Hibernate: select studentinf0_.id as id0_, studentinf0_.stuName as stuName0_,

          studentinf0_.classId as classId0_ from t_student studentinf0_ where studentinf0_.id=12
          Hibernate: select classinfo0_.claId as claId1_, classinfo0_.claName as claName1_ from t_class

          classinfo0_ where classinfo0_.claId=11
          Hibernate: select studentinf0_.id as id0_0_, studentinf0_.stuName as stuName0_0_,

          studentinf0_.classId as classId0_0_ from t_student studentinf0_ where studentinf0_.id=?
          Hibernate: update t_class set claName=? where claId=?

           

          結論:
          1對多,多的那方 cascade="all"


          **********************************
          1方, 班級:       
          **********************************
          實體類包含set對象,放置多方對象 名自取

          配置文件中配置<set>標記,標記name取本方實體中的對方set對象的名字,即set的名字 ,
          <set> 下的 <key> 指向多方主鍵
          <set> 下的 <one-to-many> 指向多方對象

           


          ***********************************
          多方  學生:       
          ***********************************
          實體類包含1方對象,名自取

          配置文件中配置<many-to-one> 指向1方對象 name 屬性取本方實體方法中的對方對象的名字。

           

           

           

           

           

           

           


           

          posted on 2009-09-10 17:38 super_nini 閱讀(384) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2009年9月>
          303112345
          6789101112
          13141516171819
          20212223242526
          27282930123
          45678910

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          相冊

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 商河县| 两当县| 万荣县| 驻马店市| 长葛市| 手机| 松潘县| 乌拉特后旗| 泰顺县| 嵊泗县| 封开县| 黄冈市| 旺苍县| 连州市| 象州县| 喜德县| 巨野县| 郓城县| 登封市| 抚松县| 新和县| 青海省| 阳春市| 富顺县| 东至县| 日土县| 醴陵市| 乌拉特中旗| 左权县| 宁津县| 玛沁县| 仙居县| 道孚县| 乌苏市| 苍南县| 商河县| 扶沟县| 蕉岭县| 湛江市| 乳山市| 泗洪县|