//大家好 我的问题是我不能在clob字段中写大日期。 curentli我可以写不超过4000长度的字符串。你能解释我为什么我不能写clob到clob领域。 我正在使用:
我的意思是:
@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)) ;
此代码在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 ;
答案 0 :(得分:0)
尝试在@LOB(type = LobType.CLOB)
访问者方法的基础上添加data
注释:
@Column(name = "VIEW_DATA", nullable = false)
@LOB(type = LobType.CLOB)
public Clob getData() {
return this.data;
}
答案 1 :(得分:0)
这是oracle驱动程序的限制。最大长度在驱动程序代码中定义为4000。 我已经尝试了许多可能的方法,但仍然是静脉。令人惊讶的是,这适用于ojbc6驱动程序。