Oracle hibernate ORA-01461 CLOB

//hi all. my problem is that i cannot write big date in clob field. curentli i can write string not greater than 4000 length. can you explain me please why i cannot write clob to clob field. im using:

  • Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
  • List item hibernate 4.2.6.Final
  • List item ojdbc 11.1.0.7.0

My entety is:

@Entity
@Table(....)
public class UiViewSettings implements java.io.Serializable {

    private Integer id;
    private String viewName;
    private String userName;
    private Clob data;
        ....
    @Column(name = "VIEW_DATA", nullable = false)
    public Clob getData() {
        return this.data;
    }
        ....
}

my code of updating entety :

UiViewSettings viewSettings = new UiViewSettings();
Clob createClob;
//creatind clob
viewSettings.setData(createClob);
session.update(viewSettings);

i tried create Clob several ways:

createClob = new SerialClob(xml.toCharArray());

and

connection = DriverManager.getConnection(...);
createClob = ((OracleConnection)connection).createClob();
createClob.setString(1, xml);

both ways throws exception :

Caused by: org.hibernate.exception.GenericJDBCException: could not execute statement
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:136)
    at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:58)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3067)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3509)
    at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:88)
    at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:377)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:369)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:286)
    at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:339)
    at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
    at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1234)
    at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:404)
    at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
    at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)


Caused by: java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column

    at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
    at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:206)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:413)
    at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:1034)
    at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:194)
    at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:953)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1222)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3387)
    at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3468)
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1350)
    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:147)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:133)

EDIT

table is

CREATE TABLE "AQUARIUS"."UI_VIEW_SETTINGS_LT" 
   (    "VIEW_ID" NUMBER NOT NULL ENABLE, 
    "VIEW_NAME" VARCHAR2(50 BYTE) NOT NULL ENABLE, 
    "USER_NAME" VARCHAR2(20 BYTE) NOT NULL ENABLE, 
    "VIEW_DATA" CLOB NOT NULL ENABLE, 
    "VERSION" NUMBER(*,0), 
    "CREATETIME" TIMESTAMP (6) WITH TIME ZONE, 
    "RETIRETIME" TIMESTAMP (6) WITH TIME ZONE, 
    "NEXTVER" VARCHAR2(500 BYTE), 
    "DELSTATUS" NUMBER(*,0), 
    "LTLOCK" VARCHAR2(100 BYTE), 
     CONSTRAINT "UI_VIEW_SETTINGS_PK" PRIMARY KEY ("VERSION", "VIEW_ID", "DELSTATUS")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS"  ENABLE NOVALIDATE
   ) SEGMENT CREATION IMMEDIATE 
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS" 
 LOB ("VIEW_DATA") STORE AS BASICFILE (
  TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION 
  NOCACHE LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)) ;

this code executes fine in SQL Developer

DECLARE
 REALLYBIGTEXTSTRING CLOB := '123';
 i int;
BEGIN

    WHILE LENGTH(REALLYBIGTEXTSTRING) <= 90000 LOOP
        REALLYBIGTEXTSTRING := REALLYBIGTEXTSTRING || '000000000000000000000000000000000';
    END LOOP;
    DBms_output.put_line('I have started inputting your clob: '|| length(REALLYBIGTEXTSTRING)); 
   INSERT INTO UI_VIEW_SETTINGS(view_id , view_name ,user_name, view_data) VALUES(0, 'test', 'test', REALLYBIGTEXTSTRING);
    DBms_output.put_line('I have finished inputting your clob: '|| length(REALLYBIGTEXTSTRING)); 
end ;

Answers


Try to add the @LOB(type = LobType.CLOB) annotation on top of your data accessor method:

@Column(name = "VIEW_DATA", nullable = false)
@LOB(type = LobType.CLOB)
public Clob getData() {
    return this.data;
}

This is limitation in oracle driver. The max length is defined as 4000 in the driver code. I've tried many possible ways but in vein. Surprisingly ,this works with ojbc6 driver.


Need Your Help

how to add a new row with pre defined data in kendo grid?

javascript jquery kendo-ui kendo-grid kendo-asp.net-mvc

I'm trying to add a new row to a kendo grid with selected data from another kendo grid. Its showing a blank row but no data. Here is my code:

Access MAMP's MySQL from Terminal

php mysql bash terminal mamp

I want to practice using SQL instead of phpMyAdmin.