Query branch_update = null;
Branches branchObject = null;
try {
branch_update = this.sessionFactory.getCurrentSession()
.createQuery("Update Branches set branchname =:branchname,update_date =:update_date WHERE branchname =:branchname1");
branch_update.setParameter("branchname", stringCellValue);
branch_update.setParameter("update_date", new Date());
branch_update.setParameter("branchname1", stringCellValue);
int update_id = branch_update.executeUpdate();
} catch (Exception exception) {
logger.error("Exception occured at \t e", exception.getMessage(), exception);
}
使用分支名称更新行时。如何获得更新的row branch_id?
提前感谢...
答案 0 :(得分:0)
您可以使用getGeneratedKeys() method获取结果集
s.execute(); // perform the UPDATE
try (ResultSet rs = s.getGeneratedKeys()) {
while (rs.next()) {
System.out.println(rs.getInt(1)); // print the "branch_id" value of the updated row
}
}
编辑: - 在那种情况下,我认为这应该有帮助
Iterator iterator = branch_update.list().iterator();
while (iterator.hasNext()) {
Branches branch = (Branches) iterator.next();
}