Jump to: navigation, search

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

< EclipseLink‎ | UserGuide‎ | JPA‎ | Basic JPA Development‎ | Mapping‎ | Basic Mappings
Revision as of 12:48, 27 October 2011 by James.sutherland.oracle.com (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

EclipseLink JPA

link="http://wiki.eclipse.org/EclipseLink"
EclipseLink
Website
Download
Community
Mailing ListForumsIRC
Bugzilla
Open
Help Wanted
Bug Day
Contribute
Browse Source

Elug api package icon.png Key API


@Basic

By default, the 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.
@Basic Attributes
Attribute Description Default Required?
fetch By default, EclipseLink persistence provider uses a fetch type of javax.persitence.FetchType.EAGER: data must be eagerly fetched. If necessary, you can 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). EAGER No
optional By default, EclipseLink persistence provider assumes that the value of all (nonprimitive) fields and properties are optional and may be null. true No


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

Example: @Basic Annotation
@Entity
public class Employee implements Serializable {
    ...
    @Basic(fetch=LAZY)
    protected String getJobDescrption() {
        return jobDescrption;
    }
    ...
}
Example: Using <basic> XML
<entity class="Employee">
    <attributes>
        ...
        <basic name="jobDescrption" fetch="LAZY"/>
        ...
    </attributes>
</entity>

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


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