6 Mapping value types

This chapter covers

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

After spending the previous chapter almost exclusively on entities and their class- and identity-mapping options, we’ll now focus on value types in their various forms. Value types are frequently encountered in classes under development. We’ll separate 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-type classes, such as Address and MonetaryAmount in CaveatEmptor.

In this chapter, we’ll first map persistent properties with JDK types and discuss the basic mapping annotations. We’ll look at how you can work with various aspects of properties: overriding defaults, customizing access, and generated values. We’ll also see how SQL is used with derived properties and transformed column values. We’ll work with basic properties, temporal properties, and mapping enumerations.

6.1 Mapping basic properties

6.1.1 Overriding basic property defaults

6.1.2 Customizing property access

6.1.3 Using derived properties

6.1.4 Transforming column values

6.1.5 Generated and default property values

6.1.6 The @Temporal annotation

6.1.7 Mapping enumerations

6.2 Mapping embeddable components

6.2.1 The database schema

6.2.2 Making classes embeddable

6.2.3 Overriding embedded attributes

6.2.4 Mapping nested embedded components

sitemap