Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Basic Mappings/Lob"
(→Example: @Lob) |
(→Database Limitations) |
||
Line 49: | Line 49: | ||
====Database Limitations==== | ====Database Limitations==== | ||
− | Some | + | Some databases have size limitations for LOB fields, or requires large LOBs be written to the database in specific ways. |
+ | |||
+ | EclipseLink supports using a LOB locator to write LOBs on Oracle. This was required to write LOBs > 4k when using the Oracle JDBC thin driver until Oracle 11g. If the <code>Oracle8Platform</code> or higher (until <code>Oracle11Platform</code>) is used LOBs will be written using a locator. This can be configured in the database platform. | ||
+ | |||
+ | EclipseLink by default binds LOB values as byte[] or String. Some databases or JDBC drivers may require stream binding. Stream binding can be configured in the database platform in code, using a <code>SessionCustomizer</code> | ||
+ | |||
{{EclipseLink_JPA | {{EclipseLink_JPA |
Revision as of 14:36, 27 October 2011
EclipseLink JPA
EclipseLink | |
Website | |
Download | |
Community | |
Mailing List • Forums • IRC • mattermost | |
Issues | |
Open • Help Wanted • Bug Day | |
Contribute | |
Browse Source |
Key API
@Lob
By default, the EclipseLink persistence provider assumes that all persistent data can be represented as typical database data types.
Use the @Lob annotation with the @Basic mapping to specify that a persistent property or field should be persisted as a large object to a database-supported large object type.
A Lob may be either a binary or character type. The persistence provider infers the Lob type from the type of the persistent field or property.
For String and character-based types, the default is Clob. In all other cases, the default is Blob.
You can also use the @Column attribute columnDefinition to further refine the Lob type.
For more information, see Section 11.1.9 "Column Annotation" in the JPA Specification.
The @Lob annotation does not have attributes.
The following example shows how to use this @Lob annotation to specify that persistent field pic should be persisted as a Blob.
Example: @Lob
@Entity public class Employee implements Serializable { ... @Lob @Basic(fetch=LAZY) @Column(name="EMP_PIC", columnDefinition="BLOB NOT NULL") protected byte[] pic; ... }
For more information, see Section 11.1.24 "Lob Annotation" in the JPA Specification.
Serialization
Although a BLOB is stored as a byte[]
, the Java a type for a @Lob
mapping can be any serializable type. JPA will automatically serialize and store the value into a BLOB field, and deserialize the value when read.
Lazy
If the LOB field is large, and may not always be required, it is normally a good idea to set its fetch
type to LAZY
using the @Basic
annotation.
Database Limitations
Some databases have size limitations for LOB fields, or requires large LOBs be written to the database in specific ways.
EclipseLink supports using a LOB locator to write LOBs on Oracle. This was required to write LOBs > 4k when using the Oracle JDBC thin driver until Oracle 11g. If the Oracle8Platform
or higher (until Oracle11Platform
) is used LOBs will be written using a locator. This can be configured in the database platform.
EclipseLink by default binds LOB values as byte[] or String. Some databases or JDBC drivers may require stream binding. Stream binding can be configured in the database platform in code, using a SessionCustomizer