hibernate配置文件注意点

一主配置文件注意点(xx.cfg.xml)
1.表的生成策略(hibernate.cfg.xml)
  <property name="hbm2ddl.auto">update</property>
create-drop (测试使用): 在Hibernate启动(session创建)的时候先删除表,在创建表   
                                                Hibernate关闭(session对象关闭)的时候删除表
create : 在Hibernate启动(session创建)的时候先删除表,在创建表   测试使用 (单个测试方法)   
validate: a.不希望映射文件改动表的结构,别人给一个sql文件,表已经先存在   b.在线运行的系统      验证表结构是否一致,如果不一致,就抛出异常  
update :   如果表不存在就创建,不一样就更新,一样就什么都不做  

2.Configuration  : hibernate的配置对象,主要用于读取配置,解析配置,最重要的功能是用来创建SessionFactory的,
 重用方法  : configure( ) ;  /  buildSessionFactory( );


二.映射文件注意点(xx.hbm.xml)
1.hibernate-mapping package = “com.hd.hibernate.xx”
    下面的class就不写包名
2.根据需要配置type , 一般只有日期才配置type属性
     年月日时分秒,年月日,时分秒
       *对于日期类型默认就是 type = "timestamp" 时间戳[yy-mm-dd hh-mm-s](年月日时分秒)
     2.1 年月日时分秒   Date createTime;
    <property name="createTime"  access="field">   datatime(全yy-mm-dd hh-mm-ss
     2.2 年月日(生日)  Date birthday; *type = "date"  年月日 
        <property name="birthday"  type="date" access="field">
     2.3 时分秒   Date time; *type = "time"  时分秒
        <property name="time" type="time" access="field">     
3.update=“false”  : 已经填写不能修改: 身份证号,生日,注册时间

4.length = “20”   unique=“true”    not-null = “true”  
(表建成后,添加unique=“true不会生效,需要删除表后,在穿件,或者使用create生成策略")
   长度           是否唯一(true:添加一个唯一约束)   非空
 
 5. auto-import : 在同一个系统下有不同包名相同类名的User
  把其中一个映射文件<hibernate-mapping package="com.ha.xx" auto-import="false">
    在使用hql查询的时候,由不方便,使用全类名来查询。则添加一个别名
          (xx.hbm.xml)<import class="com.hd.xx" rename="User2">
 
可以选择,但是别选择放弃
原文地址:https://www.cnblogs.com/hangdada/p/4983006.html