Table 1-1 JPA Annotations by Category
Category | Description | Annotations |
---|---|---|
Entity | By default, TopLink JPA assumes that a Java class is non-persistent and not eligible for JPA services unless it is decorated with this annotation. Use this annotation to designate a plain old Java object (POJO) class as an entity so that you can use it with JPA services. You must designate a class as a JPA entity (either using this annotation or the | |
Database Schema Attributes | By default, TopLink JPA assumes that an entity's name corresponds to a database table of the same name and that an entity's data member names correspond to database columns with the same names. Use these annotations to override this default behavior and fine-tune the relationship between your object model and data model. | |
Identity | By default, TopLink JPA assumes that each entity must have at least one field or property that serves as a primary key. Use these annotations to specify one of the following:
You can also use these annotations to fine-tune how your database maintains the identity of your entities. | |
Direct Mappings | By default, TopLink JPA automatically configures a Use these annotations to fine-tune how your database implements these mappings. | |
Relationship Mappings | TopLink JPA requires that you map relationships explicitly, but TopLink allows some defaulting. Use these annotations to specify the type and characteristics of entity relationships to fine-tune how your database implements these relationships. | |
Composition | Some objects cannot exist on their own, but can only be embedded within owning entities. Use these annotations to specify objects that are embedded and to override how they are mapped in the owning entity's table. | |
Inheritance | By default, TopLink JPA assumes that all persistent fields are defined by a single entity class. Use these annotations if your entity class inherits some or all persistent fields from one or more superclasses. | |
Locking | By default, TopLink JPA assumes that the application is responsible for data consistency. It is recommended that you use this annotation to enable TopLink JPA-managed optimistic locking. | |
Lifecycle Callback Events | By default, TopLink JPA handles all persistence operations. Use these annotations to associate methods with JPA lifecycle events if you need to invoke custom logic at any point during the entity lifecycle. Figure 1-1 illustrates the relationship amongst these lifecycle events. | |
Entity Manager | In an application that uses TopLink JPA, you perform all persistence operations (create, read, update, and delete) using an instance of Use these annotations to declare or inject an entity manager or entity manager factory. | |
Queries | In an application that uses TopLink JPA, you can use an entity manager to create and execute queries dynamically or you can pre-define queries and execute them by name at run time. Use these annotations to pre-define queries and manage their result sets. | |