Java Reference
In-Depth Information
You probably have a pretty good idea of exactly how O/R mapping in JPA 2 works just by
glancing at listing 2.8 , even if you have no familiarity with ORM tools such as Hibernate.
Think about the annotations that mirror relational concepts such as tables, columns, foreign
keys, and primary keys.
The @Entity annotation signifies the fact that the Bid class is a JPA entity
. The
@Table annotation tells JPA that the Bid entity is mapped to the BIDS table
. Simil-
arly, the @Column annotations ( and ) indicate which Bid properties map to which
BIDS table fields. The @Id annotation is somewhat special. It marks the Id property as
the primary key for the Bid entity . Just like a database record, a primary key uniquely
identifies an entity instance. The @GeneratedValue annotation is used to indicate
that the persistence provider should automatically generate the primary key when the en-
tity is saved into the database. The Bid entity is related to a number of other JPA entities
by holding direct object references, such the Bidder and Item entities. JPA allows such
object reference-based implicit relationships to be elegantly mapped to the database. In the
example, this is exactly what the @ManyToOne (
) and @JoinColumn (
) annotations do. In both cases, the @ManyToOne annotation indicates the nature
Search WWH ::

Custom Search