Cyh的博客

Email:kissyan4916@163.com
posts - 26, comments - 19, trackbacks - 0, articles - 220

Hibernate实体层映射 和 实体层设计

Posted on 2009-02-16 19:43 啥都写点 阅读(281) 评论(0)  编辑  收藏 所属分类: J2EE

à实体层映射:

     hibernate-mapping package="org.lxh.hibernate">

       <class name="Person" table="PERSON">

              <id name="id" column="ID" type="int">

                     <generator class="assigned" />

              </id>

              <component name="name" class="org.lxh.hibernate.Name">

                     <property name="firstname" column="FIRSTNAME" type="string" not-null="true" />

                     <property name="lastname" column="LASTNAME" type="string" not-null="true" />

              </component>

              <component name="contact" class="org.lxh.hibernate.Contact">

                     <property name="address" column="ADDRESS" type="string" not-null="true" />

                     <property name="zipcode" column="ZIPCODE" type="string" not-null="true" />

                     <property name="tel" column="TEL" type="string" />

              </component>

       </class>

</hibernate-mapping>

à实体层设计:2HBM文件的例子

|-- <hibernate-mapping package="org.lxh.hibernate04">

<class name="TItem" table="TITEM">

<id name="id" column="ID" type="string">

<generator class="assigned" />

</id>

<property name="name" column="NAME" type="string" not-null="true" />

<property name="manufacturer" column="MANUFACTURER" type="string" />

<joined-subclass name="org.lxh.hibernate04.TBook" table="TBook">

<key column="ID"></key>

<property name="pageCount" type="java.lang.Integer" column="pagecount"></property>

</joined-subclass>

<joined-subclass name="org.lxh.hibernate04.TDVD" table="TDvd">

<key column="ID"></key>

<property name="regionCode" type="java.lang.String" column="regioncode"></property>

</joined-subclass>

</class>

</hibernate-mapping>

|--  <hibernate-mapping package="org.lxh.hibernate05">

<class name="TItem" table="TITEM">

       <id name="id" column="ID" type="string">

       <generator class="assigned" />

       </id>

       <discriminator column="category" type="java.lang.String"></discriminator>

<property name="name" column="NAME" type="string" not-null="true" />

       <property name="manufacturer" column="MANUFACTURER" type="string" not-null="true" />

<subclass name="org.lxh.hibernate05.TBook" discriminator-value="1">

       <property name="pageCount" column="PAGECOUNT" type="int" />

       </subclass>

       <subclass name="org.lxh.hibernate05.TDVD" discriminator-value="2">

       <property name="regionCode" column="REGIONCODE" type="string" />

       </subclass>

       </class>

</hibernate-mapping>



                                                                                                       --    学海无涯
        


只有注册用户登录后才能发表评论。


网站导航: