Guide to Java Persistence and Hibernate Sebastian Hennebrueder
Guide to Java Persistence and HibernateSebastian Hennebrueder
Guide to Java Persistence and HibernateSebastian Hennebrueder
iii
Table of ContentsAbout the author, book and versions ................................................................................................ viii
1. The author ............................................................................................................................. viii2. The book ................................................................................................................................ viii3. Library Versions ...................................................................................................................... ix
I. Introduction ........................................................................................................................................ 11. Introduction to Hibernate ......................................................................................................... 2
1.1. A first Hibernate example ............................................................................................. 21.2. Hibernate basics ........................................................................................................... 19
2. Hibernate Concepts - State of Objects ................................................................................... 212.1. The three states of objects ........................................................................................... 212.2. Lazy initialization, a Hibernate problem ..................................................................... 23
3. Working with Objects ............................................................................................................. 273.1. Java Persistence versus Hibernate ............................................................................... 273.2. Hibernate API .............................................................................................................. 273.3. EntityManager API ...................................................................................................... 34
4. A more complex example – web application ......................................................................... 404.1. Summary ...................................................................................................................... 49
II. Mapping, Queries ........................................................................................................................... 515. Basic Mappings ...................................................................................................................... 52
5.1. Annotation versus XML .............................................................................................. 525.2. Annotation mapping ..................................................................................................... 535.3. XML Mapping ............................................................................................................. 58
6. Primary key mapping ............................................................................................................. 636.1. Natural versus Surrogate Ids ....................................................................................... 636.2. Assigned Id .................................................................................................................. 646.3. Generated with Auto Strategy ..................................................................................... 646.4. Other Annotation Strategies ........................................................................................ 646.5. Composite Id ................................................................................................................ 656.6. Equals and Hashcode ................................................................................................... 686.7. Other XML Id tags ...................................................................................................... 72
7. Relation mapping .................................................................................................................... 757.1. Selecting between List, Set, Map or array to hold many side ..................................... 757.2. Uni- and Bi-directional relations ................................................................................. 847.3. Cascading ..................................................................................................................... 867.4. 1:1 relation ................................................................................................................... 887.5. 1:n ................................................................................................................................ 947.6. m:n ............................................................................................................................. 1047.7. 1:n:1 ........................................................................................................................... 1097.8. Recursive relation ...................................................................................................... 1117.9. Typed relation (XML only) ....................................................................................... 1137.10. Typed relation (annotation workaround) ................................................................. 115
8. Components = Composition mapping .................................................................................. 1198.1. Composition versus entity relations ........................................................................... 1198.2. Composed class in one table ..................................................................................... 1208.3. Composition as set of many classes .......................................................................... 1238.4. Equals implementation ............................................................................................... 1248.5. Composition as list of many classes .......................................................................... 125
End of ebook previewDownload the full PDF tutorial from the link below :
Click Here