hibernate的映射配置

  1 <?xml version="1.0" encoding="UTF-8"?>
  2 <!DOCTYPE hibernate-mapping PUBLIC 
  3     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  4     "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
  5 <hibernate-mapping>
  6     <!-- 创建一个类与表的映射 
  7         1.name     :为类名 
  8         2.tabl     :e为表名 
  9         3.类名与表名一直是可以省略表名
 10         4.catalog  :数据库名
 11         5.lazy     :类级别的延迟加载,默认开启
 12          -->
 13     <class name="" table="" catalog="" lazy="true">
 14         <!-- 创建主键的映射 
 15             1.name为类名 
 16             2.column为列名
 17             3.length
 18             4.type
 19             
 20             -->
 21         <id name="" column="">
 22             <!-- 主键生成策略 
 23                 1.increment :hibernate中提供的自动增长机制单线程中使用
 24                 2.identity  :数据库中自动增长的主键,用于支持自动增长的数据库,mySQL,sqlserver
 25                 3.sequence  :序列化的主键,用于支持序列的数据库
 26                 4.uuid      :适用于字符类型的主键
 27                 5.native    :可以依据数据库,自主切换identity与sequence策略
 28                 6.assigned  :hibernate放弃外键的管理,需要通过手动编写程序或用户自己设置
 29                 7.foreign   :外部的.1对1的关系映射是使用
 30                 -->
 31             <generator class="increment"></generator>
 32         
 33         </id>
 34         <!-- 创建一个类的属性与表的字段的映射 
 35             1.name为类名 
 36             2.column为列名
 37             3.length
 38             4.type
 39             5.not-null 非空
 40             6.unique 唯一
 41              -->
 42         <property name="" column=""></property>
 43         <!--多对一映射 
 44             1.name   :1的对象的属性名称
 45             2.class  :1的类的全路径
 46             3.column :多的数据表中的外键的名称
 47             4.cascade:设置级联,参数:save-update,delete(两者课选其一或都选)
 48             -->
 49        <!--many-to-one 
 50                1.lazy   :关联级别的延迟加载,默认为proxy参数false关闭;proxy默认值,取决去另一端<class>上的取值;no-proxy不使用
 51             2.fetch  :抓取策略参数:select普通的select语句;join发送一条迫切左外联接查询,此时lazy失效;
 52              3.一般使用默认值lazy="proxy" fetch="select"
 53                
 54            
 55        -->
 56         <many-to-one name="" class="" column="" cascade="save-up" lazy="false" fetch="join"></many-to-one>
 57         
 58         <!--     
 59             set 中
 60             1.lazy   :关联级别的延迟加载,默认为关闭参数true;false;extra绝不多发一点语句
 61             2.fetch  :抓取策略参数:select普通的select语句;join发送一条迫切左外联接查询,此时lazy失效;subselect发送子查询
 62              3.一般使用默认值lazy="false" fetch="select
 63              
 64          -->
 65         <!--一对多映射 
 66             1.name   :多的对象集合的属性名称{1的类中的集合属性的名称}
 67             2.class  :多的类的全路径
 68             3.column :多的数据表中的外键的名称
 69             4.cascade:设置级联,参数:save-update,delete(两者课选其一或都选)
 70             5.inverse:放弃外键维护权
 71         -->
 72         <set name="" cascade="save-up" inverse="true">
 73             <key column=""></key>
 74             <one-to-many class=""/>
 75             
 76 
 77         </set>
 78         
 79         
 80         <!--多对多映射 
 81             双方类的映射都要配置
 82             也可配置成两个1对多的关系映射
 83         -->
 84         <!--set 
 85             1.name   :对方的集合属性名称
 86             2.table  :多对多的关系需要使用中间表,放的是中间表的名称
 87         -->
 88         <set name="" table="">
 89             <!--key 
 90                 1.column :当前对象对应中间表的晚间的名称
 91             -->
 92             <key column=""></key>
 93             <!--many-to-many
 94                 1.class  :对方类的全路径
 95                 2.column :对方的对象在中间表中的外键的名称
 96             -->
 97             <many-to-many class="" column=""></many-to-many>
 98         </set>
 99     </class>
100 </hibernate-mapping>
原文地址:https://www.cnblogs.com/yrxc/p/13231639.html