Web domain - 140 CHAPTER 7 n CREATING MAPPINGS WITH HIBERNATE
140 CHAPTER 7 n CREATING MAPPINGS WITH HIBERNATE XML FILES CHAPTER 7 n CREATING MAPPINGS WITH HIBERNATE XML FILES Components Lying somewhere between entities and values are component types. When the class representation is simple and its instances have a strong one-to-one relationship with instances of another class, then it is a good candidate to become a component of that other class. The component will normally be mapped as columns in the same table that represents most of the other attributes of the owning class, so the strength of the relationship must justify this inclusion. In the following code, the MacAddress class might a good candidate for a com ponent relationship. public class NetworkInterface { public int id; public String name; public String manufacturer; public MacAddress physicalAddress; } The advantage of this approach is that it allows you to dispense with the primary key of the component and the join to its containing table. If a poor choice of component is made (for example, when a many-to-one relationship actually holds), then data will be duplicated unnecessarily in the component columns. Values Everything that is not an entity or a component is a value. Generally, these correspond to the data types supported by your database, the collection types, and, optionally, some user- defined types. The details of these mappings will be vendor-specific, so Hibernate provides its own value type names; the Java types are defined in terms of these (see Table 7-1). Table 7-1. The Standard Hibernate 3 Value Names Hibernate 3 Type Corresponding Java Type Primitives and Wrappers integer int, java.lang.Integer long long, java.lang.Long short short, java.lang.Short float float, java.lang.Float double double, java.lang.Double character char, java.lang.Character byte byte, java.lang.Byte boolean, yes_no, true_false boolean, java.lang.Boolean Other Classes string java.lang.String date, time, timestamp java.util.Date calendar, calendar_date java.util.Calendar
Note: In case you are looking for affordable webhost to host and run your web application check Vision http web server services