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/Examples/JPA/Migration/OpenJPA/ColumnTypes"

< EclipseLink‎ | Examples‎ | JPA‎ | Migration‎ | OpenJPA
m
m
 
Line 30: Line 30:
 
<br>
 
<br>
 
=== CHAR(size) Return Value ===
 
=== CHAR(size) Return Value ===
In OpenJPA, when an entity defines a CHAR column with a size specified, any persisted value shorter than the size specified will be returned with extra whitespace. However, in the same scenario, EclipseLink will return the original persisted value with no extra whitespace.
+
'''''Note: this is only applicable in some databases (ie. DB2)'''''
 +
<br>
 +
In OpenJPA, when an entity defines a CHAR column with a size specified, persisted values shorter than the size specified will be returned with extra whitespace. However, in the same scenario, EclipseLink will return the original persisted value with no extra whitespace.
 
<br>
 
<br>
 
For example, for the following entity:
 
For example, for the following entity:

Latest revision as of 16:31, 9 June 2016

Differences between OpenJPA and EclipseLink: Column Type

There are a few differences between OpenJPA and EclipseLink in relation to column types.

Database Column Type

The columns added in the database tables created for each entity differ between OpenJPA and EclipseLink. When migrating from OpenJPA to EclipseLink, if a user wants to use existing tables created by OpenJPA, most of these differences will not be problematic since EclipseLink adapts to the existing column types when persisting new entities. The following table lists the field types that are created as a different column type in OpenJPA and EclipseLink.

Java Type OpenJPA EclipseLink
java.io.Serializable
java.lang.Byte[], byte[]
java.lang.Class
java.lang.String[]
BLOB(1048576) BLOB(64000)
java.lang.Boolean, boolean SMALLINT SMALLINT WITH DEFAULT 0
java.lang.Character CHAR(254) CHAR(1)
java.lang.Character[], char[] VARCHAR(254) CLOB(64000) LOGGED NOT COMPACT
java.lang.Float, float REAL DOUBLE
java.lang.String VARCHAR(254) VARCHAR(255)
java.math.BigDecimal DOUBLE DECIMAL(15,0)
enum SMALLINT INTEGER


CHAR(size) Return Value

Note: this is only applicable in some databases (ie. DB2)
In OpenJPA, when an entity defines a CHAR column with a size specified, persisted values shorter than the size specified will be returned with extra whitespace. However, in the same scenario, EclipseLink will return the original persisted value with no extra whitespace.
For example, for the following entity:

@Entity
public class Student {
…
	@Column (columnDefinition="CHAR(20)")
	private String firstName;}


The following operations are executed:

Student student = new Student();
student.setFirstName("John");
…
em.persist(student);System.out.println("Student name is (" + em.find(Student.class, id).getFirstName() + ")");


The output will be the following:

Student name is (John                )

Back to the top