我正在使用Hibernate 5和Spring 4.执行以下SQL查询并获取错误
引起:java.sql.SQLException:列数不匹配值 算在第1行
SQLQuery query = getSessionFactory().getCurrentSession().createSQLQuery(" update irms_deleted_data SET reason=:reasonStr WHERE irms_id=:id ");
query.setString("reasonStr", "ABCD1234");
query.setInteger("id", irmsData.getId());
query.executeUpdate();
我知道为什么会收到此错误?
答案 0 :(得分:0)
我尝试过(简单的hibernate示例)
create table irms_deleted_data(reason varchar2(10),irms_id number(11,0)); 插入IRMS_DELETED_DATA值(' xyz',1);
写了一个函数:
private void updateirmsDeletedData() {
Transaction tx = null;
Session session = factory.openSession();
try {
tx = session.beginTransaction();
SQLQuery query = session.createSQLQuery("update irms_deleted_data SET reason=:reasonStr WHERE irms_id=:id");
query.setString("reasonStr", "ABCD1234");
query.setInteger("id", 1);
query.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}
tx.commit();
session.close();
}
这很有效......
还可以检查irms_deleted_data上是否有触发器正在执行导致此问题的操作...