开发者

Is it necessary to flush a hibernate session when updating the id

I've come across an odd quirk in hibernate. Namely, when updating one of the properties in a composite-id, I've found I need to flush the session after the delete in order for the old record to be deleted.

session.delete(obj);
session.flush();
obj.setIdProperty1(newValue);
session.save(obj);

If the session.flush() is omitted, the original record does not get deleted. This means that two sepa开发者_如何转开发rate calls to the database need to be made instead of one when updating the id fields. I'm wondering whether the flush can be avoided so that the delete/insert can be sent as a batch?

tnx!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜