Domain Model Metadata

by Christian Bauer, Gavin King, and Gary Gregory, authors of Java Persistence with Hibernate, Second Edition

The Java Platform, Enterprise Edition (Java EE) standard solves the problem of leaky concerns with metadata as annotations in your code or as external XML descriptors. This approach allows the runtime container to implement predefined cross-cutting concerns—security, concurrency, persistence, transactions, and remoteness—in a generic way by intercepting calls to your application components. In this article, based on chapter 3 of Java Persistence with Hibernate, Second Edition, the authors discuss domain model metadata.

Metadata is data about data, so domain model metadata is information about your domain model. For example, when you use the Java Reflection API to discover the names of classes of your domain model or the names of their attributes, you access domain model metadata.

Object-relational mapping (ORM) tools also require metadata to specify the mapping between classes and tables, properties and columns, associations and foreign keys, Java types and SQL types, and so on. This ORM metadata governs the transformation between the different type systems and relationship representations in object-oriented and SQL systems. The Java Persistence API (JPA) includes a metadata API, which you can call to obtain details about the persistence aspects of your domain model, such as the names of persistent entities and attributes. Hibernate also has its own native metadata API that allows modification of the mapped SQL database table and column names dynamically. As an engineer, it