我在表插入上获得了-845个SQL代码:
nested exception is org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL
[INSERT INTO PIM30_POL_DETAILS VALUES(PREVIOUS VALUE FOR PIM_ORDER_ID_SEQ, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NULL)];
SQL state [51035]; error code [-845]; DB2 SQL Error: SQLCODE=-845, SQLSTATE=51035, SQLERRMC=SHELTRU.PIM_ORDER_ID_SEQ, DRIVER=4.17.29; nested exception is com.ibm.db2.jcc.am.SqlException: DB2 SQL Error: SQLCODE=-845, SQLSTATE=51035, SQLERRMC=SHELTRU.PIM_ORDER_ID_SEQ, DRIVER=4.17.29] with root cause
com.ibm.db2.jcc.am.SqlException: DB2 SQL Error: SQLCODE=-845, SQLSTATE=51035, SQLERRMC=SHELTRU.PIM_ORDER_ID_SEQ, DRIVER=4.17.29
这个的Java代码是:
@Transactional
public String insertIntoDatabase(final List<Policy> pols, final InspectionOrder order, final OrderReason reason){
String toReturn = PolicyDAO.transactionTemplate.execute(new TransactionCallback<String>() {
@Override
public String doInTransaction(TransactionStatus status) {
SqlParameterSource params = new BeanPropertySqlParameterSource(order);
PolicyDAO.namedParemeterJdbcTemplate.update(Queries.getInsertInspOrder(), params);
for(Policy p : pols){
params = new BeanPropertySqlParameterSource(p);
PolicyDAO.namedParemeterJdbcTemplate.update(Queries.getInsertPolDetails(), params);
}
return "Successfully ordered inspection(s)";
}
});
if(toReturn.equals("Successfully ordered inspection(s)")) return toReturn;
else return "Failed to order inspection(s)";
}
两个INSERT语句都使用一个序列,第一个使用NEXT VALUE FOR PIM_ORDER_ID_SEQ,第二个使用PREVIOUS VALUE FOR PIM_ORDER_ID_SEQ。我假设在第一次插入完成之前调用第二次插入,因为我只有5-10%的时间得到错误。
我该怎么办才能打击这个?