JPA Mini Book
www.javacodegeeks.com
Table of Contents
Reasons that led
to the creation of JPA
......................................................................................................
3
What is JPA? What is a JPA Implementation?
...........................................................................................
4
What is the persistence.xml file used for? And its configurations?
...........................................................
5
Entity definitions. What are the Logic and Physical annotations?
.............................................................
8
Id Generation: Definition, using Identity or Sequence
............................................................................
10
Identity
.................................................................................................................................................
11
Sequence
..............................................................................................................................................
12
Id Generation: TableGenerator and Auto
................................................................................................
13
TableGenerator
....................................................................................................................................
13
Auto
.....................................................................................................................................................
15
Simple Composite Key
............................................................................................................................
15
@IdClass
.............................................................................................................................................
15
@Embeddable
.....................................................................................................................................
18
Complex Composite Key
.........................................................................................................................
20
How to get an EntityManager
..................................................................................................................
24
Mapping two
or more tables in one entity
...............................................................................................
25
Mapping Hierarchy: MappedSuperclass
..................................................................................................
25
Mapping Hierarchy: Single Table
............................................................................................................
27
Mapping Hierarchy: Joined
......................................................................................................................
29
Mapping Hierarchy: Table per Concrete Class
........................................................................................
31
Pros/Cons of each hierarchy mapping approach
......................................................................................
33
Embedded Objects
...................................................................................................................................
34
ElementCollection – how to map a list of
values into a class
..................................................................
35
OneToOne unidirectional and
bidirectional
.............................................................................................
36
Unidirectional
......................................................................................................................................
36
Bidirectional
........................................................................................................................................
38
There is no such “auto relationship”
........................................................................................................
38
OneToMany/ManyToOne unidirectional and bidirectional
.....................................................................
39
There is no such “auto relationship”
........................................................................................................
40
ManyToMany unidirectional and bidirectional
........................................................................................
40
There is no such “auto relationship”
........................................................................................................
43
ManyToMany with
extra fields
................................................................................................................
43
How the Cascade functionality works? How should a developer use the OrphanRemoval? Handling the
org.hibernate.TransientObjectException
..................................................................................................
46
OrphanRemoval
...................................................................................................................................
53
How to delete an entity with relationships. Clarify which relationships are raising the exception
.........
54
Creating one EntityManagerFactory by application
................................................................................
55
Understanding how the Lazy/Eager option works
...................................................................................
56
Handling the “cannot simultaneously fetch multiple bags” error
............................................................
57
2 of 60