Java Magazine, May/June 2018
ORACLE COM JAVAMAGAZINE MAY JUNE 2018 52 design patterns The instrument model is a value object discussed next which is mapped as an embedded JPA property Value Objects Value objects are business domain types that do not represent identifiable types but rather specific values For these domain objects it doesnt matter which instance will be used inside the business process Examples of value objects are addresses money values or Java enums Value objects ideally are immutable and therefore reusable The model of an instrument is an example of a value object Instrument models that are defined by the same brand and name are identical and can be used interchangeably Value objects are mapped with JPA as embeddable objects because entities are required to define identifiers The database table of the enclosing entity type here ElectricGuitar will inline all nontransient fields of the embeddable type here Model @ Embeddable public class Model @ Basic optional false private String brand @ Basic optional false private String name protected Model required by JPA public Model String brand String name this brand brand
You must have JavaScript enabled to view digital editions.