apache openjpa 2.1 user's · pdf file apache openjpa 2.1 user's guide ... 10
Post on 30-Sep-2020
3 views
Embed Size (px)
TRANSCRIPT
Apache OpenJPA 2.1 User's Guide
Apache OpenJPA 2.1 User's Guide Built from OpenJPA version 2.1.1 revision 1148538.
Published Last updated on July 20, 2011 at 9:11 AM. Copyright © 2006-2010 The Apache Software Foundation
1. Introduction ............................................................................................................................................. 1 1. About ............................................................................................................................................. 3 2. Legal .............................................................................................................................................. 4
2.1. License ................................................................................................................................ 4 2.2. Notice .................................................................................................................................. 4 2.3. Copyrights ............................................................................................................................ 4
2.3.1. Apache ...................................................................................................................... 4 2.3.2. Serp .......................................................................................................................... 4 2.3.3. Sun ........................................................................................................................... 4 2.3.4. Other ......................................................................................................................... 5
2. Java Persistence API ................................................................................................................................. 6 1. Introduction .................................................................................................................................... 11
1.1. Intended Audience ................................................................................................................. 11 1.2. Lightweight Persistence .......................................................................................................... 11
2. Why JPA? ...................................................................................................................................... 12 3. Java Persistence API Architecture ....................................................................................................... 14
3.1. JPA Exceptions ..................................................................................................................... 15 4. Entity ............................................................................................................................................ 17
4.1. Restrictions on Persistent Classes ............................................................................................. 18 4.1.1. Default or No-Arg Constructor ...................................................................................... 18 4.1.2. Final ........................................................................................................................ 18 4.1.3. Identity Fields ............................................................................................................ 18 4.1.4. Version Field ............................................................................................................. 18 4.1.5. Inheritance ................................................................................................................ 19 4.1.6. Persistent Fields ......................................................................................................... 19 4.1.7. Conclusions ............................................................................................................... 20
4.2. Entity Identity ...................................................................................................................... 20 4.2.1. Identity Class ............................................................................................................. 21
4.2.1.1. Identity Hierarchies .......................................................................................... 22 4.3. Lifecycle Callbacks ............................................................................................................... 23
4.3.1. Callback Methods ....................................................................................................... 23 4.3.2. Using Callback Methods .............................................................................................. 24 4.3.3. Using Entity Listeners ................................................................................................. 24 4.3.4. Entity Listeners Hierarchy ............................................................................................ 25
4.4. Conclusions ......................................................................................................................... 26 5. Metadata ........................................................................................................................................ 27
5.1. Class Metadata ..................................................................................................................... 28 5.1.1. Entity ....................................................................................................................... 28 5.1.2. Id Class ..................................................................................................................... 29 5.1.3. Mapped Superclass ..................................................................................................... 29 5.1.4. Embeddable ............................................................................................................... 29 5.1.5. EntityListeners ........................................................................................................... 30 5.1.6. Example ................................................................................................................... 30
5.2. Field and Property Metadata .................................................................................................... 31 5.2.1. Explicit Access ........................................................................................................... 32 5.2.2. Transient ................................................................................................................... 33 5.2.3. Id ............................................................................................................................. 34 5.2.4. Generated Value ......................................................................................................... 34 5.2.5. Embedded Id ............................................................................................................. 35 5.2.6. Version ..................................................................................................................... 35 5.2.7. Basic ........................................................................................................................ 35
5.2.7.1. Fetch Type ...................................................................................................... 36 5.2.8. Embedded ................................................................................................................. 36 5.2.9. Many To One ............................................................................................................. 36
5.2.9.1. Cascade Type .................................................................................................. 37 5.2.10. One To Many ........................................................................................................... 38
5.2.10.1. Bidirectional Relations .................................................................................... 39 5.2.11. One To One ............................................................................................................. 39
iv
5.2.12. Many To Many ......................................................................................................... 40 5.2.13. Order By ................................................................................................................. 41 5.2.14. Map Key ................................................................................................................. 41 5.2.15. Persistent Field Defaults ............................................................................................. 41
5.3. XML Schema ....................................................................................................................... 42 5.4. Conclusion ........................................................................................................................... 60
6. Persistence ..................................................................................................................................... 65 6.1. persistence.xml ..................................................................................................................... 65 6.2. Non-EE Use ......................................................................................................................... 70
7. EntityManagerFactory ...................................................................................................................... 71 7.1. Obtaining an EntityManagerFactory .......................................................................................... 71 7.2. Obtaining