使用Spring解决CLOB字段的存取

使用Spring解决CLOB字段的存取,记录一下,以备后用zzzzzzz...
首先使用网络上提供较多的解决办法,如下配置

true

private String context;//getter & setter 然后直接save BO :报错
Caused by: java.sql.SQLException: 不允许的操作: streams type cannot be used in batching
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.driver.OraclePreparedStatement.addBatch(OraclePreparedStatement.java:4073)
at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.addBatch(DelegatingPreparedStatement.java:172)
at org.hibernate.jdbc.BatchingBatcher.addToBatch(BatchingBatcher.java:53)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2275)
... 67 more


网友介绍,可以配置,0解决上述异常;系统里到处是批量提交,此方法不可取;
还有介绍:先保存CLOB字段为空,第二次update,却遇到CLOB类型转换异常;感觉挺麻烦,继续google[切换关键字组合];

[b]下面是成功简单解决办法[/b]

writeLog() ,调用者要声明事物,没必要把writeLog放到一个独立事物里(PROPAGATION_REQUIRES_NEW)或放到嵌套事物里;
saveXXX(){ --PROPAGATION_REQUIRED即可
//business
writeLog();
}

class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"
lazy-init="true" />
class="org.springframework.jdbc.support.lob.OracleLobHandler"
lazy-init="true">







....


type="org.springframework.orm.hibernate3.support.ClobStringType"
column="context" />

private String context; //getter & setter 然后就可以使用Hibernate保存BO:OK


如果不配置事物,会报下列异常

//Spring 处理CLOB,未配置事物
Caused by: java.lang.IllegalStateException: Active Spring transaction synchronization or active JTA transaction with specified [javax.transaction.TransactionManager] required
at org.springframework.jdbc.support.lob.LobCreatorUtils.registerTransactionSynchronization(LobCreatorUtils.java:79)
at org.springframework.orm.hibernate3.support.AbstractLobType.nullSafeSet(AbstractLobType.java:185)
at org.hibernate.type.CustomType.nullSafeSet(CustomType.java:169)

文章引用: [url]http://space.itpub.net/10714335/viewspace-167565[/url]
环境:用jdk1.6.0_21+apache-tomcat-6.0.29+ojdbc14.jar+oracle10_db

你可能感兴趣的:(fw)