没有合适的资源?快使用搜索试试~ 我知道了~
首页Apache OpenJPA 2.2 用户指南:持久化数据管理框架解析
Apache OpenJPA 2.2 用户指南:持久化数据管理框架解析
需积分: 9 6 下载量 39 浏览量
更新于2024-07-27
收藏 4.18MB PDF 举报
"Apache OpenJPA 2.2 User's Guide"
Apache OpenJPA 是一个由 Apache 软件基金会维护的开源项目,它全面实现了 Java 持久化 API (Java Persistence API, JPA) 的标准,该标准是 EJB 3.0 规范的一部分。OpenJPA 为开发者提供了高效且易于使用的框架,用于处理应用程序中的持久化数据管理任务。此用户指南是针对 OpenJPA 2.2 版本编写的,详细介绍了 OpenJPA 的各种特性和用法。
在介绍部分,文档明确了 OpenJPA 的目标受众,主要面向那些希望利用轻量级持久化机制的开发者。文档还包含了法律信息,如许可证、版权声明等。Apache 开源许可证保证了软件的自由使用和分发。
Java Persistence API (JPA) 是 Java 平台上用于对象/关系映射(ORM)的标准,它简化了数据库与应用程序之间的数据交互。JPA 提供了模型化实体、定义对象关系映射、事务管理以及查询语言(JPQL)等功能。JPA 架构包括异常处理,使得开发者能够更好地理解和处理与持久化相关的错误。
在实体部分,文档详细阐述了如何定义和使用 JPA 实体。实体是应用程序中代表数据库表的对象,它们必须遵循一定的规范,如拥有默认构造函数、字段不能被 final 关键字修饰、需要有标识符字段和版本字段等。JPA 支持多种继承策略,并且可以定义生命周期回调方法,如 @PrePersist、@PostLoad 等,以及通过 EntityListeners 注解实现更灵活的监听器配置。
元数据部分介绍了 OpenJPA 如何解析和使用实体类的元数据来建立对象关系映射。元数据可以是注解形式或 XML 形式,描述了实体类的结构、属性、关系以及生命周期行为。ClassMetadata 是 OpenJPA 中的核心概念,它包含了关于单个实体类的所有持久化信息。
Apache OpenJPA 2.2 User's Guide 是一个详尽的参考资料,旨在帮助开发者充分利用 OpenJPA 实现高效的数据持久化。通过学习和理解其中的内容,开发者能够更好地设计和实现符合 JPA 标准的持久化层,从而提高应用的可维护性和扩展性。
xvi
List of Tables
2.1. Persistence Mechanisms ................................................................................................................................ 12
10.1. Interaction of ReadLockMode hint and LockManager ...................................................................................... 101
2.1. Standard JPA Properties and OpenJPA equivalents ........................................................................................... 200
4.1. Default delimiters for delimited identifiers ...................................................................................................... 248
4.2. OpenJPA Automatic Flush Behavior .............................................................................................................. 250
5.1. Externalizer Options .................................................................................................................................... 273
5.2. Factory Options .......................................................................................................................................... 274
10.1. Data access methods .................................................................................................................................. 335
10.2. Pre-defined aliases .................................................................................................................................... 346
10.3. Pre-defined aliases .................................................................................................................................... 347
15.1. Optimization Guidelines ............................................................................................................................. 370
2.1. Supported Databases and JDBC Drivers ......................................................................................................... 380
2.2. Compatible Databases and JDBC Drivers ....................................................................................................... 381
2.3. Unverified Databases and JDBC Drivers ......................................................................................................... 381
xvii
List of Examples
3.1. Interaction of Interfaces Outside Container ....................................................................................................... 15
3.2. Interaction of Interfaces Inside Container ......................................................................................................... 15
4.1. Persistent Class ............................................................................................................................................ 18
4.2. Identity Class .............................................................................................................................................. 23
5.1. Class Metadata ............................................................................................................................................ 32
5.2. Complete Metadata ....................................................................................................................................... 66
6.1. persistence.xml ............................................................................................................................................ 73
6.2. Obtaining an EntityManagerFactory ................................................................................................................. 74
7.1. Behavior of Transaction Persistence Context ..................................................................................................... 77
7.2. Behavior of Extended Persistence Context ........................................................................................................ 78
8.1. Persisting Objects ......................................................................................................................................... 84
8.2. Updating Objects ......................................................................................................................................... 84
8.3. Removing Objects ........................................................................................................................................ 85
8.4. Detaching and Merging ................................................................................................................................. 85
9.1. Grouping Operations with Transactions ............................................................................................................ 92
10.1. Query Hints ............................................................................................................................................. 101
10.2. Named Query using Hints .......................................................................................................................... 102
10.3. Setting Multiple Similar Query Hints ........................................................................................................... 103
10.4. Delete by Query ....................................................................................................................................... 105
10.5. Update by Query ...................................................................................................................................... 105
12.1. Creating a SQL Query ............................................................................................................................... 145
12.2. Retrieving Persistent Objects ....................................................................................................................... 146
12.3. SQL Query Parameters .............................................................................................................................. 146
13.1. Mapping Classes ....................................................................................................................................... 149
13.2. Defining a Unique Constraint ...................................................................................................................... 150
13.3. Identity Mapping ...................................................................................................................................... 153
13.4. Generator Mapping ................................................................................................................................... 156
13.5. Single Table Mapping ................................................................................................................................ 158
13.6. Joined Subclass Tables .............................................................................................................................. 160
13.7. Table Per Class Mapping ........................................................................................................................... 162
13.8. Inheritance Mapping .................................................................................................................................. 164
13.9. Discriminator Mapping .............................................................................................................................. 167
13.10. Basic Field Mapping ................................................................................................................................ 170
13.11. Secondary Table Field Mapping ................................................................................................................. 172
13.12. Embedded Field Mapping ......................................................................................................................... 174
13.13. Mapping Mapped Superclass Field ............................................................................................................. 175
13.14. Direct Relation Field Mapping ................................................................................................................... 178
13.15. Join Table Mapping ................................................................................................................................. 181
13.16. Join Table Map Mapping .......................................................................................................................... 183
13.17. Full Entity Mappings ............................................................................................................................... 186
2.1. Code Formatting with the Application Id Tool ................................................................................................. 198
3.1. Standard OpenJPA Log Configuration ............................................................................................................ 226
3.2. Standard OpenJPA Log Configuration + All SQL Statements ............................................................................. 226
3.3. Logging to a File ........................................................................................................................................ 226
3.4. Standard Log4J Logging .............................................................................................................................. 226
3.5. JDK Log Properties .................................................................................................................................... 227
3.6. Custom Logging Class ................................................................................................................................ 228
4.1. Properties for the OpenJPA DataSource .......................................................................................................... 232
4.2. Properties File for a Third-Party DataSource ................................................................................................... 233
4.3. Managed DataSource Configuration ............................................................................................................... 233
4.4. Setting DataSource at Runtime ..................................................................................................................... 234
4.5. Using the EntityManager's Connection ........................................................................................................... 235
Apache OpenJPA 2.2 User's Guide
xviii
4.6. Using the EntityManagerFactory's DataSource ................................................................................................. 235
4.7. Specifying a DBDictionary ........................................................................................................................... 237
4.8. Specifying a Transaction Isolation ................................................................................................................. 248
4.9. Specifying the Join Syntax Default ................................................................................................................ 249
4.10. Specifying the Join Syntax at Runtime ......................................................................................................... 249
4.11. Specifying Connection Usage Defaults ......................................................................................................... 250
4.12. Specifying Connection Usage at Runtime ...................................................................................................... 251
4.13. Enable SQL statement batching ................................................................................................................... 251
4.14. Disable SQL statement batching .................................................................................................................. 251
4.15. Plug-in custom statement batching implementation ......................................................................................... 252
4.16. Specifying Result Set Defaults .................................................................................................................... 253
4.17. Specifying Result Set Behavior at Runtime ................................................................................................... 253
4.18. Schema Creation ....................................................................................................................................... 257
4.19. SQL Scripting .......................................................................................................................................... 257
4.20. Table Cleanup .......................................................................................................................................... 257
4.21. Schema Drop ........................................................................................................................................... 257
4.22. Schema Reflection .................................................................................................................................... 257
4.23. Basic Schema ........................................................................................................................................... 259
4.24. Full Schema ............................................................................................................................................. 259
5.1. Using the OpenJPA Enhancer ....................................................................................................................... 261
5.2. Using the OpenJPA Agent for Runtime Enhancement ....................................................................................... 262
5.3. Passing Options to the OpenJPA Agent .......................................................................................................... 262
5.4. JPA Datastore Identity Metadata ................................................................................................................... 265
5.5. Finding an Entity with an Entity Identity Field ................................................................................................ 266
5.6. Id Class for Entity Identity Fields .................................................................................................................. 266
5.7. Embedded Id for Entity Identity Fields ........................................................................................................... 267
5.8. Using the Application Identity Tool ............................................................................................................... 268
5.9. Specifying Logical Inverses .......................................................................................................................... 269
5.10. Enabling Managed Inverses ........................................................................................................................ 269
5.11. Log Inconsistencies ................................................................................................................................... 270
5.12. Using Initial Field Values ........................................................................................................................... 270
5.13. Using a Large Result Set Iterator ................................................................................................................. 271
5.14. Marking a Large Result Set Field ................................................................................................................ 272
5.15. Configuring the Proxy Manager ................................................................................................................... 273
5.16. Using Externalization ................................................................................................................................ 275
5.17. Querying Externalization Fields ................................................................................................................... 275
5.18. Using External Values ............................................................................................................................... 276
5.19. Custom Fetch Group Metadata .................................................................................................................... 277
5.20. Load Fetch Group Metadata ....................................................................................................................... 278
5.21. Using the FetchPlan .................................................................................................................................. 279
5.22. Adding an Eager Field ............................................................................................................................... 279
5.23. Setting the Default Eager Fetch Mode .......................................................................................................... 281
5.24. Setting the Eager Fetch Mode at Runtime ..................................................................................................... 282
6.1. Setting a Standard Metadata Factory .............................................................................................................. 283
6.2. Setting a Custom Metadata Factory ............................................................................................................... 283
6.3. Setting the Preload Property on Metadata Repository ........................................................................................ 284
6.4. OpenJPA Metadata Extensions ...................................................................................................................... 288
6.5. OpenJPA Schema Extensions ....................................................................................................................... 289
7.1. Using the Mapping Tool .............................................................................................................................. 290
7.2. Creating the Relational Schema from Mappings ............................................................................................... 291
7.3. Refreshing entire schema and cleaning out tables ............................................................................................. 292
7.4. Dropping Mappings and Association Schema .................................................................................................. 292
7.5. Create DDL for Current Mappings ................................................................................................................ 292
7.6. Create DDL to Update Database for Current Mappings ..................................................................................... 292
Apache OpenJPA 2.2 User's Guide
xix
7.7. Configuring Runtime Forward Mapping ......................................................................................................... 293
7.8. Reflection with the Schema Tool ................................................................................................................... 293
7.9. Using the Reverse Mapping Tool .................................................................................................................. 293
7.10. Customizing Reverse Mapping with Properties ............................................................................................... 297
7.11. Validating Mappings ................................................................................................................................. 297
7.12. Configuring Mapping Defaults .................................................................................................................... 299
7.13. Standard JPA Configuration ........................................................................................................................ 300
7.14. Datastore Identity Mapping ......................................................................................................................... 302
7.15. Overriding Complex Mappings .................................................................................................................... 305
7.16. One-Sided One-Many Mapping ................................................................................................................... 307
7.17. String Key, Entity Value Map Mapping ........................................................................................................ 309
7.18. myaddress.xsd .......................................................................................................................................... 312
7.19. Address.java ............................................................................................................................................. 313
7.20. USAAddress.java ...................................................................................................................................... 313
7.21. CANAddress.java ...................................................................................................................................... 314
7.22. Showing annotated Order entity with XML mapping strategy ............................................................................ 314
7.23. Showing creation of Order entity having shipAddress mapped to XML column .................................................... 314
7.24. Sample JPQL queries for XML column mapping ............................................................................................ 315
7.25. Annotated InputStream and Reader .............................................................................................................. 315
7.26. Custom Logging Orphaned Keys ................................................................................................................. 319
8.1. Configuring Transaction Manager Integration .................................................................................................. 321
9.1. Evict from Data Cache ................................................................................................................................ 323
9.2. Using a JPA Extent .................................................................................................................................... 324
9.3. Setting Default Lock Levels ......................................................................................................................... 325
9.4. Setting Runtime Lock Levels ........................................................................................................................ 326
9.5. Locking APIs ............................................................................................................................................. 327
9.6. Disabling Locking ...................................................................................................................................... 328
9.7. Using Savepoints ........................................................................................................................................ 330
9.8. Named Seq Sequence .................................................................................................................................. 333
9.9. System Sequence Configuration .................................................................................................................... 333
10.1. Single-JVM Data Cache ............................................................................................................................. 336
10.2. Lru Cache ................................................................................................................................................ 336
10.3. Data Cache Size ....................................................................................................................................... 336
10.4. Data Cache Timeout .................................................................................................................................. 336
10.5. Excluding entities ..................................................................................................................................... 337
10.6. Including entities ...................................................................................................................................... 337
10.7. Bulk updates and cache eviction .................................................................................................................. 338
10.8. Partitioned Data Cache .............................................................................................................................. 338
10.9. Accessing the Cache .................................................................................................................................. 339
10.10. Using the javax.persistence.Cache interface .................................................................................................. 339
10.11. Accessing the StoreCache ......................................................................................................................... 339
10.12. StoreCache Usage ................................................................................................................................... 340
10.13. Automatic Data Cache Eviction ................................................................................................................. 340
10.14. Configuring CacheStatistics ....................................................................................................................... 341
10.15. Accessing the QueryResultCache ............................................................................................................... 342
10.16. Query Cache Size .................................................................................................................................... 342
10.17. Disabling the Query Cache ....................................................................................................................... 342
10.18. Query Cache Eviction Policy ..................................................................................................................... 342
10.19. Evicting Queries ..................................................................................................................................... 343
10.20. Pinning, and Unpinning Query Results ........................................................................................................ 344
10.21. Disabling and Enabling Query Caching ....................................................................................................... 344
10.22. Query Replaces Extent ............................................................................................................................. 345
10.23. Hardcoded Selection Value in JPQL Query .................................................................................................. 347
10.24. Parameterized Selection Value in JPQL Query ............................................................................................. 347
Apache OpenJPA 2.2 User's Guide
xx
12.1. Configuring Detached State ........................................................................................................................ 352
12.2. JMS Remote Commit Provider Configuration ................................................................................................ 354
12.3. TCP Remote Commit Provider Configuration ................................................................................................ 355
12.4. JMS Remote Commit Provider transmitting Persisted Object Ids ....................................................................... 355
14.1. Using the <config> Ant Tag ....................................................................................................................... 364
14.2. Using the Properties Attribute of the <config> Tag ......................................................................................... 365
14.3. Using the PropertiesFile Attribute of the <config> Tag .................................................................................... 365
14.4. Using the <classpath> Ant Tag ................................................................................................................... 365
14.5. Using the <codeformat> Ant Tag ................................................................................................................ 365
14.6. Invoking the Enhancer from Ant ................................................................................................................. 366
14.7. Invoking the Application Identity Tool from Ant ............................................................................................ 367
14.8. Invoking the Mapping Tool from Ant ........................................................................................................... 367
14.9. Invoking the Reverse Mapping Tool from Ant ............................................................................................... 368
14.10. Invoking the Schema Tool from Ant ........................................................................................................... 368
14.11. Using Commons DBCP with Apache Derby ................................................................................................ 369
2.1. Example properties for Derby ....................................................................................................................... 382
2.2. Example properties for Interbase ................................................................................................................... 382
2.3. Example properties for JDataStore ................................................................................................................. 382
2.4. Example properties for IBM DB2 .................................................................................................................. 382
2.5. Example properties for Empress .................................................................................................................... 383
2.6. Example properties for H2 Database Engine .................................................................................................... 383
2.7. Example properties for Hypersonic ................................................................................................................ 384
2.8. Example properties for Firebird ..................................................................................................................... 384
2.9. Example properties for Informix Dynamic Server ............................................................................................. 384
2.10. Example properties for Ingres ..................................................................................................................... 385
2.11. Example properties for InterSystems Cache ................................................................................................... 385
2.12. Example properties for Microsoft Access ...................................................................................................... 385
2.13. Example properties for Microsoft SQL Server ................................................................................................ 385
2.14. Example properties for Microsoft FoxPro ...................................................................................................... 386
2.15. Example properties for MySQL ................................................................................................................... 386
2.16. Using MySQL Hints .................................................................................................................................. 387
2.17. Example properties for Oracle ..................................................................................................................... 387
2.18. Using Oracle Hints .................................................................................................................................... 388
2.19. Property to disable statement batching for Oracle ........................................................................................... 388
2.20. Property to retain connection over the lifetime of the entity manager .................................................................. 388
2.21. Example properties for Pointbase ................................................................................................................. 389
2.22. Example properties for PostgreSQL ............................................................................................................. 389
2.23. Example properties for IBM solidDB ........................................................................................................... 389
2.24. Example properties for Sybase .................................................................................................................... 390
剩余414页未读,继续阅读
点击了解资源详情
点击了解资源详情
点击了解资源详情
2009-11-30 上传
2013-06-04 上传
点击了解资源详情
2010-08-05 上传
2008-03-27 上传
2011-09-21 上传
pmpper
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- JavaScript实现的高效pomodoro时钟教程
- CMake 3.25.3版本发布:程序员必备构建工具
- 直流无刷电机控制技术项目源码集合
- Ak Kamal电子安全客户端加载器-CRX插件介绍
- 揭露流氓软件:月息背后的秘密
- 京东自动抢购茅台脚本指南:如何设置eid与fp参数
- 动态格式化Matlab轴刻度标签 - ticklabelformat实用教程
- DSTUHack2021后端接口与Go语言实现解析
- CMake 3.25.2版本Linux软件包发布
- Node.js网络数据抓取技术深入解析
- QRSorteios-crx扩展:优化税务文件扫描流程
- 掌握JavaScript中的算法技巧
- Rails+React打造MF员工租房解决方案
- Utsanjan:自学成才的UI/UX设计师与技术博客作者
- CMake 3.25.2版本发布,支持Windows x86_64架构
- AR_RENTAL平台:HTML技术在增强现实领域的应用
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功