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 閱讀(388) 評論(0)  編輯  收藏

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


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

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          相冊

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 吴堡县| 宁都县| 邛崃市| 义乌市| 永安市| 平安县| 泰州市| 沧源| 潍坊市| 偏关县| 梧州市| 桃园县| 抚松县| 台江县| 兴义市| 炉霍县| 井研县| 保康县| 钦州市| 宝丰县| 安福县| 辉南县| 无极县| 巴林右旗| 毕节市| 金乡县| 邹城市| 左权县| 山东| 筠连县| 吴江市| 临潭县| 青州市| 盈江县| 浦城县| 于田县| 新沂市| 临颍县| 内江市| 津南区| 灵石县|