Search code examples
oraclejakarta-eejpaeclipselink

JPA fails when retrieving an Oracle Clob into a Java String


Because of the limitations of the VARCHAR2 type in Oracle, namely, its limit of 4000 bytes in size, I want to use the CLOB type for a column in a certain entity. So, after reading the documentation, I declared the field in my JPA entity this way:

@Column
@Lob
private String log;

I don't have any problems persisting this entity, but when I try to retrieve it with a simple SELECT m FROM Meeting m, EclipseLink complains about not being able to convert the type oracle.sql.CLOB to java.lang.String:

javax.persistence.PersistenceException: Exception [EclipseLink-3001] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.ConversionException Exception Description: The object [oracle.sql.CLOB@e9fbb9], of class [class oracle.sql.CLOB], could not be converted to [class java.lang.String]. Internal Exception: java.lang.IllegalStateException: This web container has not yet been started

I'm using Eclipselink 2.5.1 as my implementation of JPA. The database is Oracle 10g (10.2.0.3.0) and I'm using ojdbc6.jar as driver


Solution

  • Did you specify the target database platform to use? See Specifying the Database for an Application and Java Persistence API (JPA) Extensions Reference for EclipseLink, Release 2.4 for information. If it is not set, try setting it to Oracle10.