Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Basic Mappings

< EclipseLink‎ | UserGuide‎ | JPA‎ | Basic JPA Development‎ | Mapping
Revision as of 13:08, 15 June 2010 by Rick.sapir.oracle.com (Talk | contribs) (Basic Mappings)

Basic Mappings

Simple Java types are mapped as part of the immediate state of an entity in its fields or properties. Mappings of simple Java types are called basic mappings.

By default, EclipseLink persistence provider automatically configures a basic mapping for simple types.

Use the following annotations to fine-tune how your database implements these mappings:

  • @Basic
  • @Enumerated
  • @Temporal
  • @Lob
  • @Transient

For additional mapping information, see Default Conversions and Converters


@Basic

By default, EclipseLink persistence provider automatically configures @Basic mapping for most Java primitive types, wrappers of the primitive types, and enumerated types.

EclipseLink uses the default column name format of <field-name> or <property-name> in uppercase characters.

You may explicitly place an optional @Basic annotation on a field or property to explicitly mark it as persistent.

Elug note icon.png

Note: The @Basic annotation is mostly for documentation purposes – it is not required for the field or property to be persistent.


Use the @Basic annotation to do the following:

  • configure the fetch type to LAZY;
  • configure the mapping to forbid null values (for nonprimitive types) in case null values are inappropriate for your application.

The @Basic annotation has the following attributes:

  • fetch – By default, EclipseLink persistence provider uses a fetch type of javax.persitence.FetchType.EAGER: data must be eagerly fetched.If the default is inappropriate for your application or a particular persistent field, set fetch to FetchType.LAZY: this is a hint to the persistence provider that data should be fetched lazily when it is first accessed (if possible).You are not required to specify the value of this attribute.
    For more information, see What You May Need to Know About EclipseLink JPA Lazy Loading.
  • optional – By default, EclipseLink persistence provider assumes that the value of all (nonprimitive) fields and properties may be null.
    If the default is inappropriate for your application, set this the value of this attribute to false.

    You are not required to specify the value of this attribute.

This example shows how to use this annotation to specify a fetch type of LAZY for a basic mapping.


Usage of the @Basic Annotation

 @Entity
 public class Employee implements Serializable {
     ...
     @Basic(fetch=LAZY)
     protected String getName() {
         return name;
     }
     ...
 }

For more information and examples, see Section 9.1.18 "Basic Annotation" of the JPA Specification.

For more information on EclipseLink direct mappings and relationship mappings, see Relational Mapping Types.


Eclipselink-logo.gif
Version: DRAFT
Other versions...

Back to the top