oracle hibernate ora-01461 clob

sulc1iza  于 2021-07-09  发布在  Java
关注(0)|答案(2)|浏览(466)

//大家好。我的问题是我不能在clob领域写大日期。我可以写长度不超过4000的字符串。你能解释一下为什么我不能将clob写入clob字段吗。im使用:
oracle database 11g enterprise edition 11.2.0.1.0版
列表项休眠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;
    }
        ....
}

我的企业代码:

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)) ;

这段代码在sqldeveloper中执行得很好

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 ;
5vf7fwbs

5vf7fwbs1#

尝试添加 @LOB(type = LobType.CLOB) 在您的 data 访问器方法:

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

o3imoua42#

这是oracle驱动程序的限制。在驱动程序代码中,最大长度定义为4000。我试过很多可能的方法,但都是心照不宣。令人惊讶的是,这适用于ojbc6驱动程序。

相关问题