Java Reference
In-Depth Information
of the relationship between the entities. In relational terms, this means that the BIDS table
holds foreign-key references to the tables holding the Item and Bidder entities. The
@JoinColumn annotation specifies what these foreign-key references are. In the case of
the bid-item relationship, the foreign key stored in the BIDS table is ITEM_ID , which ref-
erences a key named ITEM_ID that's likely the primary key of the ITEMS table. In the
case of the bid-bidder relationship, the foreign key is BIDDER_ID and it references the
USER_ID column. Having looked at the Bid entity, let's now turn our attention to how the
entity winds up in the database through the BidDao bean.
2.4.2. Using the EntityManager
You've probably noticed that the Bid entity doesn't have a method of saving itself into the
database. The JPA EntityManager performs this bit of heavy lifting by reading the O/R
mapping configuration and providing entity persistence operations through an API-based
interface. The EntityManager knows how to store a POJO entity into the database as
a relational record, read relational data from a database and turn it into an entity, update
entity data stored in the database, and delete data mapped to an entity instance from the
database. The EntityManager has methods corresponding to each of these CRUD (cre-
ate, read, update, delete) operations, in addition to support for the robust Java Persistence
Query Language (JPQL).
Let's take a more detailed look at the BidDao in the next listing to see how some of these
EntityManager operations work.
Search WWH ::

Custom Search