全局临时表在调用存储过程时有时会引发SQL完整性约束异常



我正在尝试调试工作中的一个错误。它使用一个带有全局临时表的存储过程(在DB2中)来存储和返回结果。考虑stored_proc 中的以下代码片段

declare global temporary table session.details
(
row_count   integer not null generated always as identity,
...
)
with replace on commit delete rows not logged on rollback delete rows;

stored_proc本身由Spring框架调用。错误在于,当Spring调用stored_proc时,有时(实际上经常)我会看到类似的错误

[FMWGEN][DB2 JDBC Driver][DB2]INSERT/UPDATE INVALID; INDEX 1 RESTRICTS COLUMNS WITH SAME VALUES; 
nested exception is java.sql.SQLIntegrityConstraintViolationException: 
[FMWGEN][DB2 JDBC Driver][DB2]INSERT/UPDATE INVALID; INDEX 1 RESTRICTS COLUMNS WITH SAME VALUES

下面是调用这个stored_proc 的java代码片段

SqlParameterSource parameterSource = new MapSqlParameterSource().addValue("v_input", input)
Map<String, Object> result =  proc.execute(parameterSource);

proc是一个实例变量

private SimpleJdbcCall proc
this.proc =new SimpleJdbcCall(dataSource)
.withSchemaName("schema")
.withProcedureName("proc")
.declareParameters(
new SqlParameter("v_input", java.sql.Types.INTEGER)
).returningResultSet("output", new CustomRowMapper<String>());

根据IBMDB2文档,全局临时表在每个会话中都会被销毁和重新创建,但从sql异常来看,这似乎没有发生?感谢您的帮助。

数据库会话绑定到连接。假设您遵循了性能的一般准则,那么您就有了一个连接池。基本上,连接是重用的,因此会话永远不会被破坏。

最新更新