开发工具:
文件大小: 2mb
下载次数: 0
上传时间: 2011-08-02
详细说明: 1. 教程 ......................................................................... 1 1.1. 第一部分 - 第一个 Hibernate 应用程序 ................................. 1 1.1.1. 设置 ............................................................ 1 1.1.2. 第一个 class ................................................... 3 1.1.3. 映射文件 ........................................................ 4 1.1.4. Hibernate 配置 .................................................. 7 1.1.5. 用 Maven 构建 .................................................. 9 1.1.6. 启动和辅助类 ............ ........................................ 9 1.1.7. 加载并存储对象 ................................................. 10 1.2. 第二部分 - 关联映射 ................................................. 13 1.2.1. 映射 Person 类 ................................................ 13 1.2.2. 单向 Set-based 的关联 ......................................... 14 1.2.3. 使关联工作 ..................................................... 15 1.2.4. 值类型的集合 ................................................... 17 1.2.5. 双向关联 ....................................................... 18 1.2.6. 使双向连起来 ................................................... 19 1.3. 第三部分 - EventManager web 应用程序 ................................. 20 1.3.1. 编写基本的 servlet ............................................. 20 1.3.2. 处理与渲染 ..................................................... 21 1.3.3. 部署与测试 ..................................................... 23 1.4. 总结 ................................................................. 24 2. 体系结构(Architecture) ..................................................... 25 2.1. 概况(Overview) ...................................................... 25 2.1.1. Minimal architecture ........................................... 25 2.1.2. Comprehensive architecture ..................................... 26 2.1.3. Basic APIs .................................................... 27 2.2. JMX 整合 ............................................................. 28 2.3. 上下文相关的会话(Contextual Session) ................................ 28 3. 配置 ........................................................................ 31 3.1. 可编程的配置方式 ...................................................... 31 3.2. 获得 SessionFactory .................................................. 32 3.3. JDBC 连接 ............................................................ 32 3.4. 可选的配置属性 ........................................................ 34 3.4.1. SQL 方言 ...................................................... 41 3.4.2. 外连接抓取(Outer Join Fetching) .............................. 42 3.4.3. 二进制流(Binary Streams) ..................................... 42 3.4.4. 二级缓存与查询缓存 ............................................. 42 3.4.5. 查询语言中的替换 ............................................... 42 3.4.6. Hibernate 的统计(statistics)机制 ............................. 43 3.5. 日志 ................................................................. 43 3.6. 实现 NamingStrategy .................................................. 43 3.7. XML 配置文件 ......................................................... 44 3.8. J2EE 应用程序服务器的集成 ............................................. 45 HIBERNATE - Relational Persis... iv 3.8.1. 事务策略配置 ................................................... 46 3.8.2. JNDI 绑定的 SessionFactory ..................................... 47 3.8.3. 在 JTA 环境下使用 Current Session context(当前 session 上下文) 管理 .................................................................. 47 3.8.4. JMX 部署 ...................................................... 48 4. 持久化类(Persistent Classes) .............................................. 51 4.1. 一个简单的 POJO 例子 ................................................. 51 4.1.1. 实现一个默认的(即无参数的)构造方法(constructor) ............. 52 4.1.2. Provide an identifier property ................................. 53 4.1.3. Prefer non-final classes (semi-optional) ....................... 53 4.1.4. 为持久化字段声明访问器(accessors)和是否可变的标志(mutators) (可选) .............................................................. 54 4.2. 实现继承(Inheritance) ............................................... 54 4.3. 实现 equals() 和 hashCode() 方法: ................................... 55 4.4. 动态模型(Dynamic models) ............................................ 56 4.5. 元组片断映射(Tuplizers) ............................................. 58 4.6. EntityNameResolvers ................................................... 59 5. 对象/关系数据库映射基础(Basic O/R Mapping) ................................. 63 5.1. 映射定义(Mapping declaration) ....................................... 63 5.1.1. Entity ......................................................... 66 5.1.2. Identifiers .................................................... 71 5.1.3. Optimistic locking properties (optional) ....................... 89 5.1.4. Property ....................................................... 92 5.1.5. Embedded objects (aka components) ............................. 101 5.1.6. Inheritance strategy .......................................... 104 5.1.7. Mapping one to one and one to many associations ............... 115 5.1.8. 自然 ID(natural-id) ......................................... 123 5.1.9. Any ........................................................... 124 5.1.10. 属性(Properties) ........................................... 126 5.1.11. Some hbm.xml specificities ................................... 128 5.2. Hibernate 的类型 .................................................... 131 5.2.1. 实体(Entities)和值(values) ................................ 131 5.2.2. 基本值类型 .................................................... 132 5.2.3. 自定义值类型 .................................................. 134 5.3. 多次映射同一个类 ..................................................... 135 5.4. SQL 中引号包围的标识符 ............................................... 135 5.5. 数据库生成属性(Generated Properties) ............................... 136 5.6. Column transformers: read and write expressions ...................... 136 5.7. 辅助数据库对象(Auxiliary Database Objects) ......................... 137 6. Types ...................................................................... 139 6.1. Value types ......................................................... 139 6.1.1. Basic value types ............................................ 139 6.1.2. Composite types ............................................... 146 6.1.3. Collection types .............................................. 146 v 6.2. Entity types ........................................................ 146 6.3. Significance of type categories ..................................... 147 6.4. Custom types ........................................................ 147 6.4.1. Custom types using org.hibernate.type.Type .................... 147 6.4.2. Custom types using org.hibernate.usertype.UserType ............ 149 6.4.3. Custom types using org.hibernate.usertype.CompositeUserType .... 150 6.5. Type registry ....................................................... 151 7. 集合映射(Collection mappings) ............................................ 153 7.1. 持久化集合类(Persistent collections) ............................... 153 7.2. How to map collections .............................................. 154 7.2.1. 集合外键(Collection foreign keys) ........................... 157 7.2.2. 索引集合类(Indexed collections) ............................. 158 7.2.3. Collections of basic types and embeddable objects ............. 164 7.3. 高级集合映射(Advanced collection mappings) ......................... 166 7.3.1. 有序集合(Sorted collections) ................................ 166 7.3.2. 双向关联(Bidirectional associations) ........................ 167 7.3.3. 双向关联,涉及有序集合类 ...................................... 172 7.3.4. 三重关联(Ternary associations) .............................. 173 7.3.5. Using an ............................................. 174 7.4. 集合例子(Collection example) ....................................... 174 8. 关联关系映射 ............................................................... 181 8.1. 介绍 ................................................................ 181 8.2. 单向关联(Unidirectional associations) .............................. 181 8.2.1. 多对一(many-to-one) ......................................... 181 8.2.2. 一对一(One-to-one) .......................................... 181 8.2.3. 一对多(one-to-many) ......................................... 182 8.3. 使用连接表的单向关联(Unidirectional associations with join tables) .. 183 8.3.1. 一对多(one-to-many) ......................................... 183 8.3.2. 多对一(many-to-one) ......................................... 184 8.3.3. 一对一(One-to-one) .......................................... 184 8.3.4. 多对多(many-to-many) ........................................ 185 8.4. 双向关联(Bidirectional associations) ............................... 186 8.4.1. 一对多(one to many)/多对一(many to one) .................... 186 8.4.2. 一对一(One-to-one) .......................................... 187 8.5. 使用连接表的双向关联(Bidirectional associations with join tables) ... 188 8.5.1. 一对多(one to many)/多对一(many to one) .................... 188 8.5.2. 一对一(one to one) ......................................... 189 8.5.3. 多对多(many-to-many) ........................................ 190 8.6. 更复杂的关联映射 ..................................................... 190 9. 组件(Component)映射 ....................................................... 193 9.1. 依赖对象(Dependent objects) ........................................ 193 9.2. 在集合中出现的依赖对象(Collections of dependent objects) ........... 195 9.3. 组件作为 Map 的索引(Components as Map indices ) .................... 196 9.4. 组件作为联合标识符(Components as composite identifiers) ............ 196 HIBERNATE - Relational Persis... vi 9.5. 动态组件(Dynamic components) ....................................... 198 10. 继承映射(Inheritance Mapping) ........................................... 201 10.1. 三种策略 ............................................................ 201 10.1.1. 每个类分层结构一张表(Table per class hierarchy) ............ 201 10.1.2. 每个子类一张表(Table per subclass) ......................... 202 10.1.3. 每个子类一张表(Table per subclass),使用辨别标志 (Discriminator) .................................................... 202 10.1.4. 混合使用“每个类分层结构一张表”和“每个子类一张表” .......... 203 10.1.5. 每个具体类一张表(Table per concrete class) ................. 204 10.1.6. 每个具体类一张表,使用隐式多态 ............................... 205 10.1.7. 隐式多态和其他继承映射混合使用 ............................... 206 10.2. 限制 ............................................................... 206 11. 与对象共事 ................................................................ 209 11.1. Hibernate 对象状态(object states) ................................. 209 11.2. 使对象持久化 ........................................................ 209 11.3. 装载对象 ............................................................ 210 11.4. 查询 ............................................................... 212 11.4.1. 执行查询 ..................................................... 212 11.4.2. 过滤集合 ..................................................... 216 11.4.3. 条件查询(Criteria queries) ................................. 217 11.4.4. 使用原生 SQL 的查询 ......................................... 217 11.5. 修改持久对象 ........................................................ 218 11.6. 修改脱管(Detached)对象 ............................................ 218 11.7. 自动状态检测 ........................................................ 219 11.8. 删除持久对象 ........................................................ 220 11.9. 在两个不同数据库间复制对象 .......................................... 221 11.10. Session 刷出(flush) .............................................. 221 11.11. 传播性持久化(transitive persistence) ............................. 222 11.12. 使用元数据 ......................................................... 225 12. Read-only entities ........................................................ 227 12.1. Making persistent entities read-only ................................ 228 12.1.1. Entities of immutable classes ................................ 228 12.1.2. Loading persistent entities as read-only ..................... 228 12.1.3. Loading read-only entities from an HQL query/criteria ......... 229 12.1.4. Making a persistent entity read-only ......................... 231 12.2. Read-only affect on property type .................................. 232 12.2.1. Simple properties ............................................ 233 12.2.2. Unidirectional associations .................................. 233 12.2.3. Bidirectional associations ................................... 235 13. 事务和并发 ................................................................ 237 13.1. Session 和事务范围(transaction scope) ............................. 237 13.1.1. 操作单元(Unit of work) ..................................... 237 13.1.2. 长对话 ....................................................... 238 13.1.3. 关注对象标识(Considering object identity) .................. 239 vii 13.1.4. 常见问题 ..................................................... 240 13.2. 数据库事务声明 ...................................................... 240 13.2.1. 非托管环境 ................................................... 241 13.2.2. 使用 JTA .................................................... 242 13.2.3. 异常处理 ..................................................... 244 13.2.4. 事务超时 ..................................................... 244 13.3. 乐观并发控制(Optimistic concurrency control) ...................... 245 13.3.1. 应用程序级别的版本检查(Application version checking) ........ 245 13.3.2. 扩展周期的 session 和自动版本化 .............................. 246 13.3.3. 脱管对象(deatched object)和自动版本化 ...................... 247 13.3.4. 定制自动版本化行为 ........................................... 247 13.4. 悲观锁定(Pessimistic Locking) ..................................... 248 13.5. 连接释放模式(Connection Release Modes) ............................ 248 14. 拦截器与事件(Interceptors and events) ................................... 251 14.1. 拦截器(Interceptors) .............................................. 251 14.2. 事件系统(Event system) ............................................ 253 14.3. Hibernate 的声明式安全机制 .......................................... 254 15. 批量处理(Batch processing) .............................................. 255 15.1. 批量插入(Batch inserts) ........................................... 255 15.2. 批量更新(Batch updates) ........................................... 256 15.3. StatelessSession(无状态 session)接口 .............................. 256 15.4. DML(数据操作语言)风格的操作(DML-style operations) ............... 257 16. HQL: Hibernate 查询语言 ................................................... 261 16.1. 大小写敏感性问题 .................................................... 261 16.2. from 子句 .......................................................... 261 16.3. 关联(Association)与连接(Join) ................................... 262 16.4. join 语法的形式 .................................................... 263 16.5. 引用 identifier 属性 ............................................... 264 16.6. select 子句 ........................................................ 264 16.7. 聚集函数 ............................................................ 265 16.8. 多态查询 ............................................................ 266 16.9. where 子句 ......................................................... 267 16.10. 表达式 ............................................................. 269 16.11. order by 子句 ..................................................... 272 16.12. group by 子句 ..................................................... 273 16.13. 子查询 ............................................................. 274 16.14. HQL 示例 .......................................................... 274 16.15. 批量的 UPDATE 和 DELETE ........................................... 277 16.16. 小技巧 & 小窍门 ................................................... 277 16.17. 组件 .............................................................. 278 16.18. Row value 构造函数语法 ............................................ 279 17. 条件查询(Criteria Queries) .............................................. 281 17.1. 创建一个 Criteria 实例 ............................................. 281 17.2. 限制结果集内容 ...................................................... 281 HIBERNATE - Relational Persis... viii 17.3. 结果集排序 .......................................................... 282 17.4. 关联 ............................................................... 282 17.5. 动态关联抓取 ........................................................ 284 17.6. 查询示例 ............................................................ 284 17.7. 投影(Projections)、聚合(aggregation)和分组(grouping) ........... 285 17.8. 离线(detached)查询和子查询 ........................................ 286 17.9. 根据自然标识查询(Queries by natural identifier) ................... 287 18. Native SQL 查询 ........................................................... 289 18.1. 使用 SQLQuery ...................................................... 289 18.1.1. 标量查询(Scalar queries) ................................... 289 18.1.2. 实体查询(Entity queries) ................................... 290 18.1.3. 处理关联和集合类(Handling associations and collections) ..... 290 18.1.4. 返回多个实体(Returning multiple entities) .................. 291 18.1.5. 返回非受管实体(Returning non-managed entities) .............. 293 18.1.6. 处理继承(Handling inheritance) ............................. 293 18.1.7. 参数(Parameters) ........................................... 293 18.2. 命名 SQL 查询 ...................................................... 293 18.2.1. 使用 return-property 来明确地指定字段/别名 .................. 299 18.2.2. 使用存储过程来查询 ........................................... 300 18.3. 定制 SQL 用来 create,update 和 delete ............................. 301 18.4. 定制装载 SQL ....................................................... 304 19. 过滤数据 .................................................................. 307 19.1. Hibernate 过滤器(filters) ......................................... 307 20. XML 映射 .................................................................. 311 20.1. 用 XML 数据进行工作 ................................................ 311 20.1.1. 指定同时映射 XML 和类 ........................................ 311 20.1.2. 只定义 XML 映射 ............................................. 312 20.2. XML 映射元数据 ..................................................... 312 20.3. 操作 XML 数据 ...................................................... 314 21. 提升性能 .................................................................. 317 21.1. 抓取策略(Fetching strategies) ..................................... 317 21.1.1. 操作延迟加载的关联 ........................................... 318 21.1.2. 调整抓取策略(Tuning fetch strategies) ...................... 318 21.1.3. 单端关联代理(Single-ended association proxies) .............. 319 21.1.4. 实例化集合和代理(Initializing collections and proxies) ...... 321 21.1.5. 使用批量抓取(Using batch fetching) ......................... 322 21.1.6. 使用子查询抓取(Using subselect fetching) ................... 323 21.1.7. Fetch profile(抓取策略) .................................... 323 21.1.8. 使用延迟属性抓取(Using lazy property fetching) ............. 325 21.2. 二级缓存(The Second Level Cache) ................................. 326 21.2.1. 缓存映射(Cache mappings) ................................... 327 21.2.2. 策略:只读缓存(Strategy:read only) ........................ 329 21.2.3. 策略:读写/缓存(Strategy:read/write) ...................... 329 21.2.4. 策略:非严格读/写缓存(Strategy:nonstrict read/write) ....... 330 ix 21.2.5. 策略:事务缓存(transactional) .............................. 330 21.2.6. 各种缓存提供商/缓存并发策略的兼容性 .......................... 330 21.3. 管理缓存(Managing the caches) ..................................... 330 21.4. 查询缓存(The Query Cache) ........................................ 332 21.4.1. 启用查询缓存 ................................................. 332 21.4.2. 查询缓存区 ................................................... 333 21.5. 理解集合性能(Understanding Collection performance) ................ 333 21.5.1. 分类(Taxonomy) ............................................. 333 21.5.2. Lists,maps 和 sets 用于更新效率最高 ......................... 334 21.5.3. Bag 和 list 是反向集合类中效率最高的 ......................... 334 21.5.4. 一次性删除(One shot delete) ................................ 335 21.6. 监测性能(Monitoring performance) .................................. 335 21.6.1. 监测 SessionFactory .......................................... 335 21.6.2. 数据记录(Metrics) .......................................... 336 22. 工具箱指南 ................................................................ 339 22.1. Schema 自动生成(Automatic schema generation) ...................... 339 22.1.1. 对 schema 定制化(Customizing the schema) ................... 339 22.1.2. 运行该工具 ................................................... 342 22.1.3. 属性(Properties) ........................................... 343 22.1.4. 使用 Ant(Using Ant) ........................................ 343 22.1.5. 对 schema 的增量更新(Incremental schema updates) ........... 344 22.1.6. 用 Ant 来增量更新 schema(Using Ant for incremental schema updates) ............................................................ 344 22.1.7. Schema 校验 .................................................. 345 22.1.8. 使用 Ant 进行 schema 校验 ................................... 345 23. Additional modules ........................................................ 347 23.1. Bean Validation .................................................... 347 23.1.1. Adding Bean Validation ....................................... 347 23.1.2. Configuration ................................................ 347 23.1.3. Catching violations .......................................... 349 23.1.4. Database schema .............................................. 349 23.2. Hibernate Search ................................................... 350 23.2.1. Description .................................................. 350 23.2.2. Integration with Hibernate Annotations ....................... 350 24. 示例:父子关系(Parent/Child) ............................................. 351 24.1. 关于 collections 需要注意的一点 ..................................... 351 24.2. 双向的一对多关系(Bidirectional one-to-many) ....................... 351 24.3. 级联生命周期(Cascading lifecycle) ................................. 353 24.4. 级联与未保存值(unsaved-value) ..................................... 354 24.5. 结论 ............................................................... 355 25. 示例:Weblog 应用程序 ..................................................... 357 25.1. 持久化类(Persistent Classes) ...................................... 357 25.2. Hibernate 映射 ..................................................... 358 25.3. Hibernate 代码 ..................................................... 360 HIBERNATE - Relational Persis... x 26. 示例:复杂映射实例 ........................................................ 365 26.1. Employer(雇主)/Employee(雇员) ................................... 365 26.2. Author(作家)/Work(作品) ......................................... 367 26.3. Customer(客户)/Order(订单)/Product(产品) ...................... 369 26.4. 杂例 ............................................................... 371 26.4.1. "Typed" 一对一关联 ........................................... 371 26.4.2. 组合键示例 ................................................... 371 26.4.3. 共有组合键属性的多对多(Many-to-many with shared composite key attribute) .......................................................... 373 26.4.4. 基于内容的识别 ............................................... 374 26.4.5. 备用键的联合 ................................................. 375 27. 最佳实践(Best Practices) ................................................ 377 28. 数据库移植性考量 .......................................................... 381 28.1. 移植性基础 .......................................................... 381 28.2. Dialect ............................................................. 381 28.3. 方言的使用 .......................................................... 381 28.4. 标识符的生成 ........................................................ 382 28.5. 数据库函数 .......................................................... 383 28.6. 类型映射 ............................................................ 383 参考资料 ....................................................................... 385 ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.