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

Difference between revisions of "EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Basic Mappings"

m (@Basic)
m (@Basic)
Line 36: Line 36:
 
* configure the fetch type to <tt>LAZY</tt><nowiki>;</nowiki>
 
* configure the fetch type to <tt>LAZY</tt><nowiki>;</nowiki>
 
* configure the mapping to forbid null values (for nonprimitive types) in case null values are inappropriate for your application.
 
* configure the mapping to forbid null values (for nonprimitive types) in case null values are inappropriate for your application.
{{EclipseLink_AttributeTable|caption=@Basic Attributes|content=<tr>
+
{{EclipseLink_AttributeTable
 +
|caption=@Basic Attributes
 +
|content=<tr>
 
  <td>'''<tt>fetch</tt>'''</td>
 
  <td>'''<tt>fetch</tt>'''</td>
  <td> By default, EclipseLink persistence provider uses a fetch type of <tt>javax.persitence.FetchType.EAGER</tt><nowiki>: data must be eagerly fetched. If necessary, you can set <tt>fetch</tt> to <tt>FetchType.LAZY</tt>: this is a hint to the persistence provider that data should be fetched lazily when it is first accessed (if possible).
+
  <td> By default, EclipseLink persistence provider uses a fetch type of <tt>javax.persitence.FetchType.EAGER</tt>: data must be eagerly fetched. If necessary, you can set <tt>fetch</tt> to <tt>FetchType.LAZY</tt>: this is a hint to the persistence provider that data should be fetched lazily when it is first accessed (if possible).
 
{{EclipseLink_Note
 
{{EclipseLink_Note
 
|note=For more information, see [[Using%20EclipseLink%20JPA%20Extensions%20(ELUG)#What You May Need to Know About EclipseLink JPA Lazy Loading|What You May Need to Know About EclipseLink JPA Lazy Loading]].}}
 
|note=For more information, see [[Using%20EclipseLink%20JPA%20Extensions%20(ELUG)#What You May Need to Know About EclipseLink JPA Lazy Loading|What You May Need to Know About EclipseLink JPA Lazy Loading]].}}
 
</td>
 
</td>
 
  <td>Eager</td>
 
  <td>Eager</td>
  <td>No></td>
+
  <td>No</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>

Revision as of 15:06, 17 June 2010

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.

For all mapping types there are a common set of options:

  • Read-Only: Specifies that the mapping should populate the value on read and copy. Required when multiple mappings share the same database column.
    See Configuring Read-Only Mappings in the EclipseLink User's Guide for details.
  • Converters allow custom data types and data conversions to be used with most mapping types
    • Annotations: @Converter, @TypeConverter, @ObjectTypeConverter, @StructConverter, @Convert
    • XML: <converter>, <type-converter>, <object-type-converter>, <struct-converter>, <convert>
    See Converters and Transformers in the EclipseLink User's Guide for details.

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.
@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

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...

Copyright © Eclipse Foundation, Inc. All Rights Reserved.