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

From Eclipsepedia

Jump to: navigation, search
m
(Example: @Transient Annotation)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{EclipseLink_UserGuide|info=y|toc=n}}
+
{{EclipseLink_UserGuide
 +
|info=y
 +
|toc=n
 +
|eclipselink=y
 +
|eclipselinktype=JPA
 +
|api=y
 +
|apis=
 +
* [http://www.eclipse.org/eclipselink/api/latest/javax/persistence/Transient.html @Transient]
 +
}}
 +
 
 
=@Transient=
 
=@Transient=
 
By default, EclipseLink persistence provider assumes that all the fields of an entity are persistent.
 
By default, EclipseLink persistence provider assumes that all the fields of an entity are persistent.
  
Use the <tt>@Transient</tt> annotation to specify a field or property of an entity that is not persistent (for example, a field or property that is used at run time, but that is not part of the entity's state).
+
Use the <tt>@Transient</tt> annotation or <code><nowiki><transient></nowiki></code> XML to specify a field or property of an entity that is not persistent (for example, a field or property that is used at run time, but that is not part of the entity's state).
  
 
EclipseLink persistence provider will not persist (or create database schema) for a property or field annotated with <tt>@Transient</tt>.
 
EclipseLink persistence provider will not persist (or create database schema) for a property or field annotated with <tt>@Transient</tt>.
  
This annotation can be used with <tt>@Entity</tt>, [[#@MappedSuperclass|<tt>@MappedSuperclass</tt>]]), and [[#@Embeddable|<tt>@Embeddable</tt>]].
+
This annotation can be used with <tt>@Entity</tt>, <tt>@MappedSuperclass</tt>, and <tt>@Embeddable</tt>.
 
{{EclipseLink_Spec
 
{{EclipseLink_Spec
 
|section=Section 8.1 "Entity"}}
 
|section=Section 8.1 "Entity"}}
Line 13: Line 22:
 
The <tt>@Transient</tt> annotation does not have attributes.
 
The <tt>@Transient</tt> annotation does not have attributes.
  
The [[#Example 18-16|Usage of the @Transient Annotation]] example shows how to use the <tt>@Transient</tt> annotation to specify <tt>Employee</tt> field <tt>currentSession</tt> as not persistent. EclipseLink persistence provider will not persist this field.
+
If a field is marked as Java <code>transient</code> it will also be ignored.
  
 +
The following example shows how to use the <tt>@Transient</tt> annotation to specify <tt>Employee</tt> field <tt>currentSession</tt> as not persistent. EclipseLink persistence provider will not persist this field.
  
<span id="Example 18-16"></span>
+
======'' Example: @Transient Annotation''======
''''' Usage of the @Transient Annotation'''''
+
 
<source lang="java">
 
<source lang="java">
@Entity
+
@Entity
public class Employee implements Serializable {
+
public class Employee implements Serializable {
    ...
+
    @Id
    @Id
+
    int id;
    int id;
+
 
+
    @Transient
    @Transient
+
    Session currentSession;
    Session currentSession;
+
    ...
    ...
+
}
}
+
</source>
 +
 
 +
======''Example: Using <code><nowiki><transient></nowiki></code> XML''======
 +
<source lang="xml">
 +
<entity class="Employee">
 +
    <attributes>
 +
        <id name="id"/>
 +
        <transient name="currentSession"/>
 +
        ...
 +
    </attributes>
 +
</entity>
 
</source>
 
</source>
  
 
{{EclipseLink_Spec
 
{{EclipseLink_Spec
|section=Section 9.1.16 "Transient Annotation"}}
+
|section=Section 11.1.48 "Transient Annotation"}}
  
  

Latest revision as of 15:16, 27 October 2011

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


[edit] @Transient

By default, EclipseLink persistence provider assumes that all the fields of an entity are persistent.

Use the @Transient annotation or <transient> XML to specify a field or property of an entity that is not persistent (for example, a field or property that is used at run time, but that is not part of the entity's state).

EclipseLink persistence provider will not persist (or create database schema) for a property or field annotated with @Transient.

This annotation can be used with @Entity, @MappedSuperclass, and @Embeddable.

Elug javaspec icon.gif

For more information, see Section 8.1 "Entity" in the JPA Specification.

The @Transient annotation does not have attributes.

If a field is marked as Java transient it will also be ignored.

The following example shows how to use the @Transient annotation to specify Employee field currentSession as not persistent. EclipseLink persistence provider will not persist this field.

[edit] Example: @Transient Annotation
@Entity
public class Employee implements Serializable {
    @Id
    int id;
 
    @Transient
    Session currentSession;
    ...
}
[edit] Example: Using <transient> XML
<entity class="Employee">
    <attributes>
        <id name="id"/>
        <transient name="currentSession"/>
        ...
    </attributes>
</entity>
Elug javaspec icon.gif

For more information, see Section 11.1.48 "Transient Annotation" in the JPA Specification.


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