File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes Using CLOBs with JPA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Using CLOBs with JPA" Watch "Using CLOBs with JPA" New topic

Using CLOBs with JPA

Blue Rider Abc Murnau

Joined: Aug 02, 2006
Posts: 4
Hi there

I have a table with a column of type CLOB (I'm using Oracle 10g)
Here I want to store a large set of characters (around 100k).

On the Java side I've created an entity with the JPA annotations.
For the clob element I use the following declaration:

@Column(name="DATA", columnDefinition="CLOB NOT NULL")
public String getData() {
return data;

In the persistence.xml file I declare that Oracle jdbc driver be used:
<property name="toplink.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/>

Now, whenever I try to insert a long string the following exception happens:

"java.sql.SQLException: setString can only process strings of less than 32766 chararacters"

I wonder if someone else has had this problem before?

If this were a limitation of the jdbc driver, then how can we work with
clob (lobs) elments transparently using JPA?

Blue Rider Abc Murnau

Joined: Aug 02, 2006
Posts: 4
Right, I found a solution; I simply updated the oracle jdbc driver
,ojdbc14.jar, to the latest release ( R2).
This has fixed the problem.
Now I can persist transparently CLOBs using JPA.
Mike Keith
Ranch Hand

Joined: Jul 14, 2005
Posts: 304
Indeed. The newer Oracle JDBC drivers have actually gotten a LOT better.

Pro JPA 2: Mastering the Java Persistence API
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

"Blue Rider Abc Murnau"

Please click on the My Profile link above and change your display name to match the JavaRanch Naming Policy of using your real first and last names.

Also note, that users that don't follow the naming policy can NOT win a book.



Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: Using CLOBs with JPA
jQuery in Action, 3rd edition