当前位置: 首页 > 知识库问答 >
问题:

Oracle hibernate ORA-01461 CLOB

闻人浩波
2023-03-14

//大家好。我的问题是我不能在clob字段中写大日期。curentli我可以写长度不大于4000的字符串。你能解释一下为什么我不能写clob到clob字段。我正在使用:

  • Oracle数据库11g企业版11.2.0.1.0
  • 列表项hibernate 4.2.6.final
  • 列表项ojdbc 11.1.0.7.0

我的恩典是:

@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;
    }
        ....
}

我更新entety的代码:

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

我尝试了几种方法来创建Clob:

createClob = new SerialClob(xml.toCharArray());
connection = DriverManager.getConnection(...);
createClob = ((OracleConnection)connection).createClob();
createClob.setString(1, xml);
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)
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)) ;
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 ;

共有1个答案

邓仲卿
2023-03-14

尝试在data访问器方法的顶部添加@lob(type=lobtype.clob)注释:

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

相关问答

相关文章

相关阅读