Skip to main content

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.

Jump to: navigation, search

EclipseLink/Examples/JPA/Migration/OpenJPA/ColumnTypes

< EclipseLink‎ | Examples‎ | JPA‎ | Migration‎ | OpenJPA
Revision as of 16:06, 9 June 2016 by Daliasheasha.gmail.com (Talk | contribs) (Differences between OpenJPA and EclipseLink: Basic Column Types)

Differences between OpenJPA and EclipseLink: 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


Additional Differences: 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.
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