Book Image

EJB 3 Developer Guide

By : Michael Sikora
Book Image

EJB 3 Developer Guide

By: Michael Sikora

Overview of this book

Table of Contents (18 chapters)
EJB 3 Developer Guide
Credits
About the Author
About the Reviewers
Preface
Annotations and Their Corresponding Packages

O/R Mapping Default Behavior


In the previous chapter we saw how to persist individual entities to a relational database. In this chapter, we take a further look at object-relational mapping with EJB 3. In any real world application, entities do not exist in isolation but have relationships with other entities. In this chapter we shall see how these relationships are mapped onto a relational database.

Object-relational mapping is specified using annotations, but XML mapping files can be used as an alternative. Annotations make extensive use of defaulting. This means that not only do we not have to specify any annotation options if we are satisfied with the defaults, but in many cases we do not have to provide an annotation itself. In this case a default annotation is used.

This defaulting capability is particularly helpful in cases where we start from a Java object model and derive our database schema from this model. However, if we are mapping our Java model to an existing database schema...