有没有一种方法可以通过以下方式取回受影响的行数:
getHibernateTemplate().save(bean);
如果你不知道最后发生了什么,使用保存有什么意义。
或者,如果我插入一个新行,我想获得创建的新 PK AI....
有什么想法吗?
谢谢
最佳答案
is there a way that i get back the number of affected rows by using:
不是针对“保存”操作,这是可以理解的。但是,如果您使用的是 Query
,则 executeUpdate
方法会返回受影响的记录数。
what is the point using save if you dont know what happened in the end.
好吧,如果没有异常(exception),你可以假设一切都按预期进行。
Or, if i insert a new row, i want to get the new PK AI that was created....
Hibernate 使用生成的 PK 更新持久化 bean。所以,如果你的 bean 有一个 long id
,设置为自动递增,Hibernate 将在它被持久化后填充这个字段。
关于java - getHibernateTemplate.save() - 如何获得受影响的行/新的自动增量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4859676/