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/Basic"

m
(Example: @Basic Annotation)
 
(8 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
|toc=n
 
|toc=n
 
|eclipselink=y
 
|eclipselink=y
|eclipselinktype=JPA}}
+
|eclipselinktype=JPA
 +
|api=y
 +
|apis=
 +
* [http://www.eclipse.org/eclipselink/api/latest/javax/persistence/Basic.html @Basic]
 +
}}
  
 
=@Basic=
 
=@Basic=
By default, EclipseLink persistence provider automatically configures <tt>@Basic</tt> mapping for most Java primitive types, wrappers of the primitive types, and enumerated types.
+
By default, the EclipseLink persistence provider automatically configures <tt>@Basic</tt> mapping for most Java primitive types, wrappers of the primitive types, and enumerated types.
  
EclipseLink uses the default column name format of <tt><field-name></tt> or <property-name> in uppercase characters.
+
EclipseLink uses the default column name format of <tt><field-name></tt> or <tt><property-name></tt> in uppercase characters.
  
 
You may explicitly place an optional <tt>@Basic</tt> annotation on a field or property to explicitly mark it as persistent.
 
You may explicitly place an optional <tt>@Basic</tt> annotation on a field or property to explicitly mark it as persistent.
Line 25: Line 29:
 
  <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).
 
  <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).
 
</td>
 
</td>
  <td>Eager</td>
+
  <td><code>EAGER</code></td>
 
  <td>No</td>
 
  <td>No</td>
 
</tr>
 
</tr>
Line 31: Line 35:
 
  <td>'''<tt>optional</tt>'''</td>
 
  <td>'''<tt>optional</tt>'''</td>
 
  <td>By default, EclipseLink persistence provider assumes that the value of all (nonprimitive) fields and properties are optional and may be <tt>null</tt>.</td>
 
  <td>By default, EclipseLink persistence provider assumes that the value of all (nonprimitive) fields and properties are optional and may be <tt>null</tt>.</td>
  <td>True</td>
+
  <td><code>true</code></td>
 
  <td>No</td>
 
  <td>No</td>
 
</tr>
 
</tr>
Line 41: Line 45:
 
======'' Example: @Basic Annotation''======
 
======'' Example: @Basic Annotation''======
 
<source lang="java">
 
<source lang="java">
@Entity
+
@Entity
public class Employee implements Serializable {
+
public class Employee implements Serializable {
    ...
+
    ...
    @Basic(fetch=LAZY)
+
    @Basic(fetch=LAZY)
    protected String getName() {
+
    protected String getJobDescrption() {
        return name;
+
        return jobDescrption;
    }
+
    }
    ...
+
    ...
}
+
}
 
</source>
 
</source>
 +
======''Example: Using <code><nowiki><basic></nowiki></code> XML''======
  
For more information and examples, see Section 9.1.18 "Basic Annotation" of the [http://jcp.org/en/jsr/detail?id=220 JPA Specification].
+
<source lang="xml">
 +
<entity class="Employee">
 +
    <attributes>
 +
        ...
 +
        <basic name="jobDescrption" fetch="LAZY"/>
 +
        ...
 +
    </attributes>
 +
</entity>
 +
</source>
  
For more information on EclipseLink direct mappings and relationship mappings, see [[Introduction%20to%20Relational%20Mappings%20(ELUG)#Relational Mapping Types|Relational Mapping Types]].
+
For more information and examples, see Section 11.1.6 "Basic Annotation" of the [http://jcp.org/en/jsr/detail?id=220 JPA Specification].
  
  

Latest revision as of 13:48, 27 October 2011

EclipseLink JPA

Eclipselink-logo.gif
EclipseLink
Website
Download
Community
Mailing ListForumsIRCmattermost
Issues
OpenHelp WantedBug 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...

Back to the top