一,源码功能模块
1. org.hibernate :该包的类基本上都是接口类和异常类
2. org.hibernate.cache.* :cache的实现类
3. org.hibernate.cfg.* :配置文件读取类
4. org.hibernate.collection.* :Hibernate集合接口实现类:例如List(PersistentList),Set(PersistentSet), Bag(PersistentBag)等等,Hibernate之所以要自行编写集合接口实现类是为了支持延迟加载。
5. org.hibernate.connection.* :几个数据库连接池的Provider
6. org.hibernate.dialect.* :支持多种数据库特性,每个Dialect实现类代表一种数据库,描述了该数据库支持的数据类型和其它特点,例如是否有AutoIncrement,是否有Sequence,是否有分页sql等等
7. org.hibernate.eg.* :Hibernate文档中用到的例子
8. org.hibernate.engine.* :这个包的类作用比较散
9. org.hibernate.hql.* :HQL的实现org.hibernate.id.* :ID生成器
10. orghibernate.impl.* :最核心的包,一些重要接口的实现类,如果Session,SessionFactory,Query等
11. org.hibernate.jca.* :JCA支持,把Session包装为支持JCA的接口实现类
12. org.hibernate.jmx.* :jmx的实现
13. org.hibernate.loader.* :也是很核心的包,主要是生成sql语句的
14. org..hibernate.lob.* :Blob和Clob支持
15. org.hibernate.mapping.* :hbm文件的属性实现
16. org.hibernate.metadata.*:PO的Meta实现
17. org.hibernate.odmg.*:ODMG是一个ORM标准,这个包是ODMG标准的实现类
18. org.hibernate.persister.*:核心包,实现持久对象和表之间的映射
19. org.hibernate.proxy.*:Proxy和Lazy Loading支持
20. org.hibernate.ps.*:该包是PreparedStatment Cache
21. org.hibernate.sql.*:生成JDBC sql语句的包
22. org.hibernate.test.*:测试类,你可以用junit来测试Hibernate
23. org.hibernate.tool.hbm2ddl.*:用hbm配置文件生成DDL
24. org.hibernate.transaction.*:Hibernate Transaction实现类
25. org.hibernate.type.*:Hibernate中定义的持久对象的属性的数据类型
26. org.hibernate.util.*:一些工具类,作用比较散
27. org.hibernate.xml.*:XML数据绑定
二,关键类与接口
Environment类:环境变量key的配置 基本和hibernate。properties对应
Setting类:存放系统配置信息转换的对象
Configuration类:系统配置信息
Sessionfactory(SessionfactoryImpl):session工厂类 用于产生session
CurrentSessionContext(ThreadLocalSessionContext):session对象 用于存储session
ConnectionProvider(DriverManageConnectionProvider):驱动管理类
三,Hibernate启动
Configuration config=new Configuration()
.addClass(xx.class)
.addClass(xx.class)
.addClass(xx.calss)
.setProperty();
config.Configuration();
text.factory=config.buildSessionFactory();
分析:
1,new Configuration();
Configuration的构造函数:
protect Configuration(SettingsFactory settingFactory){
this.settingFactory=settingFactory();
reset();
}
public Configuration(){
this(new SettingFactory());
}
SettingFactory的构造函数:
protect SettingFactory(){
}
在new一个configuration的时候调用调用protect构造函数;Configuration用处是读取..cfg.xml中的系统配置;
然后再把这个东西交给SettingFactory处理
2,构造函数中的reset方法
reset做了很多事情 但是主要初始化一些东西和Environment.getPropertoes();
这个方法主要是用作读取hibernate.properties的
public static Properties getProperties(){
Properties pro=new Properties();
pro.putAll(GLOBAL_PROPERTIES);
}
注:GLOBAL_PROPERTIES是启动的时候静态代码快读取的hibernate.properties
3,addClass(xx.class)
通过传入对像.getname 然后用String解析再+hbm.xml
然后就是加载这个配置文件了
4,setPropertoes设置配置文件的key和value
5,config.Configuration();系统默认加载cfg.xml 这样会覆盖hibernate.properties的配置文件信息
6,config.buildSessionFactory()创建session
四,hibernate的hbm.xml的配置和处理类;
1,如何配置:
2,如何处理:
五,HQL语句的写法和处理类:
(后续再整理)
评论