Java Reference
In-Depth Information
entity. Recall that the @Table annotation specifies that the bid record should be saved in
the BIDS table, while each of the @Column and @JoinColumn annotations in listing 2.7
tells JPA which Bid entity field maps to which column in the BIDS table. For example,
the Id property maps to the BIDS.BID_ID column, the amount property maps to the
BIDS.BID_AMOUNT column, and so on. As we discussed earlier, the @Id and @Gener-
atedValue value annotations specify that the BID_ID column is the primary key of the
BIDS table and that the JPA provider should automatically generate a value for the column
before the INSERT statement is issued (the 52 value in the SQL sample). This process of
translating an entity to columns in the database is exactly what O/R mapping and JPA is all
about.
In a similar vein to the persist method, the find method retrieves an entity by the
primary key, the merge method updates an entity in the database, and the remove meth-
od deletes an entity.
This brings us to the end of this brief introduction to the Java Persistence API—and to the
end of this whirlwind chapter. At this point, it should be clear to you how simple, effective,
and robust EJB 3 is, even from a bird's-eye view.
2.5. Summary
As we stated in the introduction, the goal of this chapter wasn't to feed you the “guru pill”
for EJB 3 but rather to show you what to expect from this new version of the Java Enter-
prise platform.
This chapter introduced the ActionBazaar application, a central theme to this topic. Using a
scenario from the ActionBazaar application, we showed you a cross-section of EJB 3 func-
tionality, including stateless session beans, stateful session beans, CDI, JSF 2, and JPA 2.
You learned some basic concepts such as metadata annotations, dependency injection, and
O/R mapping.
You used a stateless session bean to implement the business logic for placing a bid for an
item in an auctioning system. You then saw a stateful session bean that encapsulated the lo-
gic for ordering an item. You saw how EJB 3 components can be unit-tested via JUnit and
how JSF 2, CDI, and EJB 3 work together seamlessly across application tiers. Finally, we
Search WWH ::




Custom Search