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