关闭

hibernate hbm.xml配置文件说明

5205人阅读 评论(0) 收藏 举报

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//hibernate/Hibernate Mapping DTD 2.0//EN"
                    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>

   <class name="com.oreilly.hh.Track" table="TRACK">
     <meta attribute="class-description">
        Represents a single playable track in the music database.
        @author Jim Elliot(with help from Hibernate)
     </meta>
    
     <id name="id" type="int" column="TRACK_ID">
       <meta attribute="scope-set">protected</meta>
          <generator class="native"/>
     </id>
    
     <property name="title" type="string" not-null="true"/>
    
     <property name="filePath" type="string" not-null="true"/>
    
     <property name="playTime" type="time">
        <meta attribute="field-description">Playing time</meta>
     </property>
    
     <property name="added" type="date">
        <meta attribute="field-description">When the track was created</meta>
     </property>
    
     <property name="volume" type="short" not-null="true">
        <meta attribute="field-description">How loud to play the track</meta>
     </property>
    
   </class>
</hibernate-mapping>
     说明如下:

1.<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//hibernate/Hibernate Mapping DTD 2.0//EN"
                    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>

用于导言说明,说明它的文件格式定义。

2.<hibernate-mapping>标签里是真正的映射。

3.<class name="com.oreilly.hh.Track" table="TRACK">
定义一个类com.oreilly.hh.Track的映射。(可以定义任意多个类在一个映射文件里)。表示存在数据库表TRACK中。

4. <meta attribute="class-description">
        Represents a single playable track in the music database.
        @author Jim Elliot(with help from Hibernate)
     </meta>
定义了说明,可以被JavaDoc读取。

5.  <id name="id" type="int" column="TRACK_ID">
       <meta attribute="scope-set">protected</meta>
          <generator class="native"/>
     </id>
 定义了类属性和数据库表列的映射。   <generator class="native"/>是表示ID生成策略,此种策略有多种。

6. <property name="volume" type="short" not-null="true">
        <meta attribute="field-description">How loud to play the track</meta>
  </property>                                                                                                                                                                                          定义了说明,可以被JavaDoc读取。




 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:7440次
    • 积分:97
    • 等级:
    • 排名:千里之外
    • 原创:2篇
    • 转载:0篇
    • 译文:0篇
    • 评论:2条
    文章存档
    最新评论