您好,欢迎光临本网站![请登录][注册会员]  
文件名称: hibernate_reference3.1
  所属分类: Java
  开发工具:
  文件大小: 1000kb
  下载次数: 0
  上传时间: 2011-09-14
  提 供 者: ti***
 详细说明: Table of Contents Preface .......................................................................................................................................... viii 1. Introduction to Hibernate ........................................................................................................... 1 1.1. Preface .............................................................................................................................. 1 1.2. Part 1 - The first Hibernate Application ..................................... .......................................... 1 1.2.1. The first class .......................................................................................................... 1 1.2.2. The mapping file ..................................................................................................... 3 1.2.3. Hibernate configuration ........................................................................................... 4 1.2.4. Building with Ant .................................................................................................... 6 1.2.5. Startup and helpers .................................................................................................. 6 1.2.6. Loading and storing objects ...................................................................................... 8 1.3. Part 2 - Mapping associations ............................................................................................ 10 1.3.1. Mapping the Person class ....................................................................................... 10 1.3.2. A unidirectional Set-based association .................................................................... 11 1.3.3. Working the association ......................................................................................... 12 1.3.4. Collection of values ............................................................................................... 13 1.3.5. Bi-directional associations ..................................................................................... 14 1.3.6. Working bi-directional links ................................................................................... 15 1.4. Part 3 - The EventManager web application ....................................................................... 16 1.4.1. Writing the basic servlet ........................................................................................ 16 1.4.2. Processing and rendering ....................................................................................... 17 1.4.3. Deploying and testing ............................................................................................ 18 1.5. Summary ......................................................................................................................... 19 2. Architecture .............................................................................................................................. 20 2.1. Overview ......................................................................................................................... 20 2.2. Instance states .................................................................................................................. 22 2.3. JMX Integration ............................................................................................................... 22 2.4. JCA Support .................................................................................................................... 23 2.5. Contextual Sessions .......................................................................................................... 23 3. Configuration ............................................................................................................................ 25 3.1. Programmatic configuration .............................................................................................. 25 3.2. Obtaining a SessionFactory ............................................................................................... 25 3.3. JDBC connections ............................................................................................................ 26 3.4. Optional configuration properties ...................................................................................... 27 3.4.1. SQL Dialects ......................................................................................................... 32 3.4.2. Outer Join Fetching ............................................................................................... 33 3.4.3. Binary Streams ...................................................................................................... 34 3.4.4. Second-level and query cache ................................................................................. 34 3.4.5. Query Language Substitution ................................................................................. 34 3.4.6. Hibernate statistics ................................................................................................ 34 3.5. Logging ........................................................................................................................... 34 3.6. Implementing a NamingStrategy ....................................................................................... 35 3.7. XML configuration file ..................................................................................................... 35 3.8. J2EE Application Server integration .................................................................................. 36 3.8.1. Transaction strategy configuration .......................................................................... 37 3.8.2. JNDI-bound SessionFactory ................................................................................... 38 3.8.3. Current Session context management with JTA ....................................................... 38 3.8.4. JMX deployment ................................................................................................... 39 4. Persistent Classes ...................................................................................................................... 40 Hibernate 3.1.2 ii 4.1. A simple POJO example ................................................................................................... 40 4.1.1. Implement a no-argument constructor ..................................................................... 41 4.1.2. Provide an identifier property (optional) .................................................................. 41 4.1.3. Prefer non-final classes (optional) ........................................................................... 41 4.1.4. Declare accessors and mutators for persistent fields (optional) .................................. 42 4.2. Implementing inheritance ................................................................................................. 42 4.3. Implementing equals() and hashCode() .............................................................................. 42 4.4. Dynamic models .............................................................................................................. 43 4.5. Tuplizers ......................................................................................................................... 45 5. Basic O/R Mapping ................................................................................................................... 47 5.1. Mapping declaration ......................................................................................................... 47 5.1.1. Doctype ................................................................................................................ 48 5.1.2. hibernate-mapping ................................................................................................. 48 5.1.3. class ..................................................................................................................... 49 5.1.4. id .......................................................................................................................... 51 5.1.4.1. Generator ................................................................................................... 52 5.1.4.2. Hi/lo algorithm ........................................................................................... 53 5.1.4.3. UUID algorithm ......................................................................................... 53 5.1.4.4. Identity columns and sequences ................................................................... 53 5.1.4.5. Assigned identifiers .................................................................................... 54 5.1.4.6. Primary keys assigned by triggers ................................................................ 54 5.1.5. composite-id ......................................................................................................... 54 5.1.6. discriminator ......................................................................................................... 55 5.1.7. version (optional) .................................................................................................. 56 5.1.8. timestamp (optional) .............................................................................................. 56 5.1.9. property ................................................................................................................ 57 5.1.10. many-to-one ........................................................................................................ 58 5.1.11. one-to-one ........................................................................................................... 60 5.1.12. natural-id ............................................................................................................ 62 5.1.13. component, dynamic-component .......................................................................... 62 5.1.14. properties ............................................................................................................ 63 5.1.15. subclass .............................................................................................................. 64 5.1.16. joined-subclass .................................................................................................... 64 5.1.17. union-subclass ..................................................................................................... 65 5.1.18. join ..................................................................................................................... 66 5.1.19. key ..................................................................................................................... 67 5.1.20. column and formula elements ............................................................................... 67 5.1.21. import ................................................................................................................. 68 5.1.22. any ..................................................................................................................... 68 5.2. Hibernate Types ............................................................................................................... 69 5.2.1. Entities and values ................................................................................................. 69 5.2.2. Basic value types ................................................................................................... 70 5.2.3. Custom value types ............................................................................................... 71 5.3. Mapping a class more than once ........................................................................................ 72 5.4. SQL quoted identifiers ...................................................................................................... 72 5.5. Metadata alternatives ........................................................................................................ 72 5.5.1. Using XDoclet markup .......................................................................................... 73 5.5.2. Using JDK 5.0 Annotations .................................................................................... 74 5.6. Generated Properties ........................................................................................................ 75 5.7. Auxiliary Database Objects ............................................................................................... 75 6. Collection Mapping ................................................................................................................... 77 6.1. Persistent collections ........................................................................................................ 77 HIBERNATE - Relational Persistence for Idiomatic Java Hibernate 3.1.2 iii 6.2. Collection mappings ......................................................................................................... 77 6.2.1. Collection foreign keys .......................................................................................... 79 6.2.2. Collection elements ............................................................................................... 79 6.2.3. Indexed collections ................................................................................................ 79 6.2.4. Collections of values and many-to-many associations .............................................. 80 6.2.5. One-to-many associations ...................................................................................... 82 6.3. Advanced collection mappings .......................................................................................... 82 6.3.1. Sorted collections .................................................................................................. 82 6.3.2. Bidirectional associations ....................................................................................... 83 6.3.3. Bidirectional associations with indexed collections .................................................. 84 6.3.4. Ternary associations .............................................................................................. 85 6.3.5. Using an .................................................................................................. 86 6.4. Collection examples ......................................................................................................... 86 7. Association Mappings ............................................................................................................... 89 7.1. Introduction ..................................................................................................................... 89 7.2. Unidirectional associations ............................................................................................... 89 7.2.1. many to one .......................................................................................................... 89 7.2.2. one to one ............................................................................................................. 89 7.2.3. one to many .......................................................................................................... 90 7.3. Unidirectional associations with join tables ........................................................................ 91 7.3.1. one to many .......................................................................................................... 91 7.3.2. many to one .......................................................................................................... 91 7.3.3. one to one ............................................................................................................. 92 7.3.4. many to many ....................................................................................................... 92 7.4. Bidirectional associations ................................................................................................. 92 7.4.1. one to many / many to one ..................................................................................... 93 7.4.2. one to one ............................................................................................................. 93 7.5. Bidirectional associations with join tables .......................................................................... 94 7.5.1. one to many / many to one ..................................................................................... 94 7.5.2. one to one ............................................................................................................. 95 7.5.3. many to many ....................................................................................................... 96 7.6. More complex association mappings ................................................................................. 96 8. Component Mapping ................................................................................................................ 98 8.1. Dependent objects ............................................................................................................ 98 8.2. Collections of dependent objects ....................................................................................... 99 8.3. Components as Map indices ............................................................................................ 100 8.4. Components as composite identifiers ............................................................................... 100 8.5. Dynamic components ..................................................................................................... 102 9. Inheritance Mapping ............................................................................................................... 103 9.1. The Three Strategies ....................................................................................................... 103 9.1.1. Table per class hierarchy ...................................................................................... 103 9.1.2. Table per subclass ............................................................................................... 104 9.1.3. Table per subclass, using a discriminator ............................................................... 104 9.1.4. Mixing table per class hierarchy with table per subclass ......................................... 105 9.1.5. Table per concrete class ....................................................................................... 105 9.1.6. Table per concrete class, using implicit polymorphism ........................................... 106 9.1.7. Mixing implicit polymorphism with other inheritance mappings ............................. 107 9.2. Limitations .................................................................................................................... 107 10. Working with objects ............................................................................................................ 109 10.1. Hibernate object states .................................................................................................. 109 10.2. Making objects persistent .............................................................................................. 109 10.3. Loading an object ......................................................................................................... 110 HIBERNATE - Relational Persistence for Idiomatic Java Hibernate 3.1.2 iv 10.4. Querying ..................................................................................................................... 111 10.4.1. Executing queries .............................................................................................. 111 10.4.1.1. Iterating results ....................................................................................... 112 10.4.1.2. Queries that return tuples ......................................................................... 112 10.4.1.3. Scalar results .......................................................................................... 112 10.4.1.4. Bind parameters ...................................................................................... 112 10.4.1.5. Pagination .............................................................................................. 113 10.4.1.6. Scrollable iteration .................................................................................. 113 10.4.1.7. Externalizing named queries .................................................................... 114 10.4.2. Filtering collections ........................................................................................... 114 10.4.3. Criteria queries .................................................................................................. 115 10.4.4. Queries in native SQL ........................................................................................ 115 10.5. Modifying persistent objects ......................................................................................... 115 10.6. Modifying detached objects .......................................................................................... 116 10.7. Automatic state detection .............................................................................................. 116 10.8. Deleting persistent objects ............................................................................................ 117 10.9. Replicating object between two different datastores ........................................................ 118 10.10. Flushing the Session ................................................................................................... 118 10.11. Transitive persistence ................................................................................................. 119 10.12. Using metadata ........................................................................................................... 120 11. Transactions And Concurrency ............................................................................................. 122 11.1. Session and transaction scopes ...................................................................................... 122 11.1.1. Unit of work ...................................................................................................... 122 11.1.2. Long conversations ............................................................................................ 123 11.1.3. Considering object identity ................................................................................. 124 11.1.4. Common issues ................................................................................................. 125 11.2. Database transaction demarcation .................................................................................. 125 11.2.1. Non-managed environment ................................................................................ 126 11.2.2. Using JTA ......................................................................................................... 127 11.2.3. Exception handling ............................................................................................ 128 11.2.4. Transaction timeout ........................................................................................... 128 11.3. Optimistic concurrency control ...................................................................................... 129 11.3.1. Application version checking ............................................................................. 129 11.3.2. Extended session and automatic versioning ......................................................... 130 11.3.3. Detached objects and automatic versioning ......................................................... 130 11.3.4. Customizing automatic versioning ...................................................................... 131 11.4. Pessimistic Locking ...................................................................................................... 131 11.5. Connection Release Modes ........................................................................................... 132 12. Interceptors and events ......................................................................................................... 134 12.1. Interceptors .................................................................................................................. 134 12.2. Event system ................................................................................................................ 135 12.3. Hibernate declarative security ....................................................................................... 136 13. Batch processing .................................................................................................................... 138 13.1. Batch inserts ................................................................................................................ 138 13.2. Batch updates ............................................................................................................... 138 13.3. The StatelessSession interface ....................................................................................... 139 13.4. DML-style operations ................................................................................................... 139 14. HQL: The Hibernate Query Language .................................................................................. 142 14.1. Case Sensitivity ............................................................................................................ 142 14.2. The from clause ............................................................................................................ 142 14.3. Associations and joins .................................................................................................. 142 14.4. Forms of join syntax ..................................................................................................... 144 HIBERNATE - Relational Persistence for Idiomatic Java Hibernate 3.1.2 v 14.5. The select clause .......................................................................................................... 144 14.6. Aggregate functions ..................................................................................................... 145 14.7. Polymorphic queries ..................................................................................................... 145 14.8. The where clause .......................................................................................................... 146 14.9. Expressions .................................................................................................................. 147 14.10. The order by clause .................................................................................................... 150 14.11. The group by clause .................................................................................................... 150 14.12. Subqueries ................................................................................................................. 151 14.13. HQL examples ........................................................................................................... 151 14.14. Bulk update and delete ................................................................................................ 153 14.15. Tips & Tricks ............................................................................................................. 153 15. Criteria Queries .................................................................................................................... 155 15.1. Creating a Criteria instance ........................................................................................... 155 15.2. Narrowing the result set ................................................................................................ 155 15.3. Ordering the results ...................................................................................................... 156 15.4. Associations ................................................................................................................. 156 15.5. Dynamic association fetching ........................................................................................ 157 15.6. Example queries ........................................................................................................... 157 15.7. Projections, aggregation and grouping ........................................................................... 158 15.8. Detached queries and subqueries ................................................................................... 159 15.9. Queries by natural identifier .......................................................................................... 159 16. Native SQL ............................................................................................................................ 161 16.1. Using a SQLQuery ....................................................................................................... 161 16.2. Alias and property references ........................................................................................ 162 16.3. Named SQL queries ..................................................................................................... 163 16.3.1. Using return-property to explicitly specify column/alias names ............................. 164 16.3.2. Using stored procedures for querying .................................................................. 165 16.3.2.1. Rules/limitations for using stored procedures ............................................ 165 16.4. Custom SQL for create, update and delete ...................................................................... 166 16.5. Custom SQL for loading ............................................................................................... 167 17. Filtering data ......................................................................................................................... 168 17.1. Hibernate filters ........................................................................................................... 168 18. XML Mapping ...................................................................................................................... 170 18.1. Working with XML data ............................................................................................... 170 18.1.1. Specifying XML and class mapping together ....................................................... 170 18.1.2. Specifying only an XML mapping ...................................................................... 170 18.2. XML mapping metadata ............................................................................................... 171 18.3. Manipulating XML data ............................................................................................... 172 19. Improving performance ........................................................................................................ 174 19.1. Fetching strategies ........................................................................................................ 174 19.1.1. Working with lazy associations .......................................................................... 175 19.1.2. Tuning fetch strategies ....................................................................................... 175 19.1.3. Single-ended association proxies ........................................................................ 176 19.1.4. Initializing collections and proxies ...................................................................... 177 19.1.5. Using batch fetching .......................................................................................... 178 19.1.6. Using subselect fetching ..................................................................................... 179 19.1.7. Using lazy property fetching ............................................................................... 179 19.2. The Second Level Cache ............................................................................................... 180 19.2.1. Cache mappings ................................................................................................ 180 19.2.2. Strategy: read only ............................................................................................. 181 19.2.3. Strategy: read/write ............................................................................................ 181 19.2.4. Strategy: nonstrict read/write .............................................................................. 181 HIBERNATE - Relational Persistence for Idiomatic Java Hibernate 3.1.2 vi 19.2.5. Strategy: transactional ........................................................................................ 182 19.3. Managing the caches .................................................................................................... 182 19.4. The Query Cache ......................................................................................................... 183 19.5. Understanding Collection performance .......................................................................... 184 19.5.1. Taxonomy ......................................................................................................... 184 19.5.2. Lists, maps, idbags and sets are the most efficient collections to update ................. 185 19.5.3. Bags and lists are the most efficient inverse collections ........................................ 185 19.5.4. One shot delete .................................................................................................. 185 19.6. Monitoring performance ............................................................................................... 186 19.6.1. Monitoring a SessionFactory .............................................................................. 186 19.6.2. Metrics ............................................................................................................. 186 20. Toolset Guide ........................................................................................................................ 188 20.1. Automatic schema generation ........................................................................................ 188 20.1.1. Customizing the schema ..................................................................................... 188 20.1.2. Running the tool ................................................................................................ 190 20.1.3. Properties .......................................................................................................... 191 20.1.4. Using Ant ......................................................................................................... 191 20.1.5. Incremental schema updates ............................................................................... 192 20.1.6. Using Ant for incremental schema updates .......................................................... 192 20.1.7. Schema validation ............................................................................................. 193 20.1.8. Using Ant for schema validation ......................................................................... 193 21. Example: Parent/Child .......................................................................................................... 194 21.1. A note about collections ................................................................................................ 194 21.2. Bidirectional one-to-many ............................................................................................. 194 21.3. Cascading lifecycle ....................................................................................................... 195 21.4. Cascades and unsaved-value ......................................................................................... 196 21.5. Conclusion ................................................................................................................... 197 22. Example: Weblog Application ............................................................................................... 198 22.1. Persistent Classes ......................................................................................................... 198 22.2. Hibernate Mappings ..................................................................................................... 199 22.3. Hibernate Code ............................................................................................................ 200 23. Example: Various Mappings ................................................................................................. 204 23.1. Employer/Employee ..................................................................................................... 204 23.2. Author/Work ................................................................................................................ 205 23.3. Customer/Order/Product ............................................................................................... 207 23.4. Miscellaneous example mappings .................................................................................. 209 23.4.1. "Typed" one-to-one association .......................................................................... 209 23.4.2. Composite key example ..................................................................................... 209 23.4.3. Many-to-many with shared composite key attribute ............................................. 211 23.4.4. Content based discrimination .............................................................................. 212 23.4.5. Associations on alternate ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: hibernate_reference.pdf
 输入关键字,在本站1000多万海量源码库中尽情搜索: