Hibernate , Domain models and metadata


In this article

    Discovering the CaveatEmptor example application
■    Implementing the domain model
■    Object/relational mapping metadata options
The “Hello World” example in the previous article introduced you to Hibernate; certainly, it isn’t useful for understanding the requirements of real-world applications with complex data models. For the rest of the article, we use a much more sophisticated example application—CaveatEmptor, an online auction system—to demonstrate Hibernate and Java Persistence. ( Caveat emptor means “Let the buyer beware”.)
Major new features in JPA 2
■    A JPA persistence provider now integrates automatically with a Bean Validation provider. When data is stored, the provider automatically validates constraints on persistent classes.
■    The Metamodel API has been added. You can obtain (unfortunately not change) the names, properties, and mapping metadata of the classes in a persistence unit.
We’ll start our discussion of the application by introducing a layered application architecture. Then, you’ll learn how to identify the business entities of a problem domain. You’ll create a conceptual model of these entities and their attributes, called a domain model, and you’ll implement it in Java by creating persistent classes. We’ll spend some time exploring exactly what these Java classes should look like and where they fit within a typical layered application architecture. We’ll also look at the persistence capabilities of the classes and how this aspect influences the design and implementation. We’ll add Bean Validation, which helps to automatically verify the integrity of the domain model data not only for persistent information but all business logic.
We’ll then explore mapping metadata options—the ways you tell Hibernate how your persistent classes and their properties relate to database tables and columns. This can be as simple as adding annotations directly in the Java source code of the classes or writing XML documents that you eventually deploy along with the compiled Java classes that Hibernate accesses at runtime. After reading this chapter, you’ll know how to design the persistent parts of your domain model in complex real-world projects, and what mapping metadata option you’ll primarily prefer and use. Let’s start with the example application.

Comments