Apache web server - CHAPTER 3 Domain models and metadata The Hello

CHAPTER 3 Domain models and metadata The Hello World example in the previous chapter introduced you to Hibernate; however, it isn t useful for understanding the requirements of real-world applications with complex data models. For the rest of the book, we use a much more sophisticated example application CaveatEmptor, an online auction system to demonstrate Hibernate and Java Persistence. We start our discussion of the application by introducing a programming model for persistent classes. Designing and implementing the persistent classes is a multistep process that we ll examine in detail. First, you ll learn how to identify the business entities of a problem domain. You create a conceptual model of these entities and their attributes, called a domain model, and you implement it in Java by creating persistent classes. We spend some time exploring exactly what these Java classes should look like, and we also look at the persistence capabilities of the classes, and how this aspect influences the design and implementation. We then explore mapping metadata options the ways you can tell Hibernate how your persistent classes and their properties relate to database tables and columns. This can involve writing XML documents that are eventually deployed along with the compiled Java classes and are read by Hibernate at runtime. Another option is to use JDK 5.0 metadata annotations, based on the EJB 3.0 standard, directly in the Java source code of the persistent classes. 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. Finally, in the last (probably optional) section of this chapter, we look at Hibernate s capability for representation independence. A relatively new feature in Hibernate allows you to create a domain model in Java that is fully dynamic, such as a model without any concrete classes but only HashMaps. Hibernate also supports a domain model representation with XML documents. Let s start with the example application. 3.1 The CaveatEmptor application The CaveatEmptor online auction application demonstrates ORM techniques and Hibernate functionality; you can download the source code for the application from http://caveatemptor.hibernate.org. We won t pay much attention to the user interface in this book (it could be web based or a rich client); we ll concentrate instead on the data access code. However, when a design decision about data
We recommend high quality webhost to host and run your jsp application: christian web host services.