Chapter 5. Mapping value types

 

In this chapter

  • Mapping basic properties
  • Mapping embeddable components
  • Controlling mapping between Java and SQL types

After spending the previous chapter almost exclusively on entities and the respective class- and identity-mapping options, we now focus on value types in their various forms. We split value types into two categories: basic value-typed classes that come with the JDK, such as String, Date, primitives, and their wrappers; and developer-defined value-typed classes, such as Address and MonetaryAmount in CaveatEmptor.

In this chapter, we first map persistent properties with JDK types and learn the basic mapping annotations. You see how to work with various aspects of properties: overriding defaults, customizing access, and generated values. You also see how SQL is used with derived properties and transformed column values. We wrap up basic properties with temporal properties and mapping enumerations. We then discuss custom value-typed classes and map them as embeddable components. You learn how classes relate to the database schema and make your classes embeddable, while allowing for overriding embedded attributes. We complete embeddable components by mapping nested components. Finally, we discuss how to customize loading and storing of property values at a lower level with flexible JPA converters, a standardized extension point of every JPA provider.

5.1. Mapping basic properties

5.1.1. Overriding basic property defaults

5.1.2. Customizing property access

5.1.3. Using derived properties

5.1.4. Transforming column values

5.1.5. Generated and default property values

5.1.6. Temporal properties

5.1.7. Mapping enumerations

5.2. Mapping embeddable components

5.2.1. The database schema

5.2.2. Making classes embeddable

5.2.3. Overriding embedded attributes

5.2.4. Mapping nested embedded components

5.3. Mapping Java and SQL types with converters

5.3.1. Built-in types

sitemap