title: Large Hibernate insert into CLOB field in DB2 results in error
body: <p>I have an entity that has one field mapped to a CLOB:</p>
  
  <pre><code>// Entity variable
  @Lob
  private String payload;
  
  
  -- DDL
  CREATE TABLE "MYENTITY" (
      "PAYLOAD" CLOB,
       ... 
  );
  </code></pre>
  
  <p>While persisting this entity with Hibernate, it works well for small Strings (&lt;1MB) but strings above 1MB does not work. DB2 is complaining that the value is too large (SQLCODE=-302, SQLSTATE=22001) but as far as I know, a CLOB can be 2GB-ish. I have not defined any length restriction whatsoever on the column.</p>
  
  <p><strong>Question:</strong>
  What am I missing here? Is there any length restriction or max size field I cannot see through?</p>
  
  <p>I'm thankful for any clue that lead to solving this problem.</p>
  
  <p>DB: IBM DB2 9.7 LUW
  JPA: Hibernate 3.3.2</p>
  
  <p>Stacktrace:</p>
  
  <pre><code>  org.hibernate.exception.DataException: could not insert: [com.example.MyEntity]
  at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:100) 
  at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) 
  at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:64) 
  at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2176) 
  at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2656) 
  at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71) 
  at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279) 
  at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321) 
  at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204) 
  at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130) 
  at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:49)
  at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:154) 
  at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:110)
  at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61) 
  at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:646) 
  at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:620) 
  at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:624)
  at 
  
  org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:220) 
      ... 110 common frames omitted
  Caused by: com.ibm.db2.jcc.am.eo: DB2 SQL Error: SQLCODE=-302, SQLSTATE=22001, SQLERRMC=null, DRIVER=4.7.85
      at com.ibm.db2.jcc.am.dd.a(dd.java:668) ~[db2jcc4.jar:na]
      at com.ibm.db2.jcc.am.dd.a(dd.java:60) ~[db2jcc4.jar:na]
      at com.ibm.db2.jcc.am.dd.a(dd.java:127) ~[db2jcc4.jar:na]
      at com.ibm.db2.jcc.am.nm.c(nm.java:2493) ~[db2jcc4.jar:na]
      at com.ibm.db2.jcc.am.nm.a(nm.java:1977) ~[db2jcc4.jar:na]
      at com.ibm.db2.jcc.t4.db.n(db.java:801) ~[db2jcc4.jar:na]
      at com.ibm.db2.jcc.t4.db.i(db.java:258) ~[db2jcc4.jar:na]
      at com.ibm.db2.jcc.t4.db.c(db.java:53) ~[db2jcc4.jar:na]
      at com.ibm.db2.jcc.t4.t.c(t.java:44) ~[db2jcc4.jar:na]
      at com.ibm.db2.jcc.t4.sb.i(sb.java:147) ~[db2jcc4.jar:na]
      at com.ibm.db2.jcc.am.nm.ib(nm.java:1972) ~[db2jcc4.jar:na]
      at com.ibm.db2.jcc.am.om.b(om.java:3553) ~[db2jcc4.jar:na]
      at com.ibm.db2.jcc.am.om.Yb(om.java:710) ~[db2jcc4.jar:na]
      at com.ibm.db2.jcc.am.om.executeUpdate(om.java:689) ~[db2jcc4.jar:na]
      at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94) 
      at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)
  </code></pre>