【发布时间】:2015-03-07 13:48:48
【问题描述】:
在我的项目中,我使用hibernate hbm 和spring,我运行sql 查询来更新单个列,
Query sql = getSession().createSQLQuery("update HISTORIQUE_DETAIL_APPELS set token_otp = '"+historiqueDetailAppelsVO.getCodeOtp()+"' where id = '"+historiqueDetailAppelsVO.getId()+"'");
try {
sql.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}
我发现执行了另一个查询并更新了数据库中的表,
Hibernate: update HISTORIQUE_DETAIL_APPELS set token_otp = '14d3fc' where id = '150017'
Hibernate: update HISTORIQUE_DETAIL_APPELS set cod_cent=?, adresse_ip=?, id_conseiller=?, type_piece=?, num_piece_ident=?, msisdn=?, mois1_detail=?, mois2_detail=?, mois3_detail=?, date_demande=?, no_ticket_caisse=?, date_ticket=?, cod_user=?, dat_maj=?, flag_imp_data=?, date_imp_data=?, token_otp=?, send_mail=?, client_mail=?, date_debut=?, date_fin=? where id=?
第二次更新的起源在哪里?
【问题讨论】:
-
第二次查询是否影响数据库中的记录?
-
@GuillaumeS 是的,它会影响数据库中的记录
-
但它只是更新 token_otp ?
-
@GuillaumeS 它会更新其他列
-
@GuillaumeS 我找到了解决方案,请参阅我的答案
标签: java spring hibernate jakarta-ee hibernate-criteria