CHAPTER 7 n CREATING MAPPINGS WITH HIBERNATE XML (My web server)

CHAPTER 7 n CREATING MAPPINGS WITH HIBERNATE XML FILES 143 n CREATING MAPPINGS WITH HIBERNATE XML FILES 143 THE ORDER AND CARDINALITY INFORMATION FROM THE DTD The mapping files used by Hibernate have a great many elements and are somewhat self-referential. For example, the element permits you to include within it further elements, and within those further elements and so on, ad infinitum. While we do not quote exhaustively from the mapping file s DTD, we sometimes quote the part of it that specifies the permitted ordering and cardinality (number of occurrences) of the child elements of a given element. The cardinality is expressed by a symbol after the end of the name of the element: * means zero or more occurrences, ? means zero or one occurrences, and no trailing symbol means exactly one occurrence. The elements can be grouped using brackets, and where the elements are interchangeable, | (the pipe symbol) means or. In practical terms, this allows us to tell from the order and cardinality information quoted for the hibernate-mapping file that all of the elements immediately below it are, in fact, optional. We can also see that there is no limit to the number of elements that can be included. You can look up this ordering and cardinality information in the DTD for the mapping file for all the elements, including the ones that we have omitted from this chapter. You will also find within the DTD the specification of which attributes are permitted to each element, the values they may take (when they are constrained), and their default values when provided. We recommend that you look at the DTD for enlight- enment whenever you are trying to work out whether a specific mapping file should be syntactically valid. Throughout this book, we have assumed that the mappings are defined in one mapping file for each significant class that is to be mapped to the database. We suggest that you follow this practice in general, but there are some exceptions to this rule. You may, for instance, find it useful to place query and sql-query entries into an independent mapping file, particularly when they do not fall clearly into the context of a single class. The Element The child element that you will use most often indeed, in nearly all of your mapping files is . As you have seen in earlier chapters, we generally describe the relationships between Java objects and database entities in the body of the element. The element permits the following attributes to be defined (see Table 7-3). Table 7-3. The Attributes Attribute Values Default Description abstract true, false false The flag that should be set if the class being mapped is abstract. batch-size 1 Specifies the number of items that can be batched together when retrieving instances of the class by identifier. catalog The database catalog against which the queries should apply. Continued
You want to have a cheap webhost for your apache application, then check apache web hosting services.

Leave a Reply