本文介绍了额外的由Hibernate生成的sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  beginTransaction(); 

使用session.save保存对象如下:
sessionFactory.getCurrentSession()。save(entity);
entity.setName(Entity+ Math.random());
commitTransaction();

生成以下sql:

 


为什么它应该生成单独的更新sql,即使在更改后尽快更新? 解决方案

这是预期的Hibernate行为正如Gavin(其中一位hibernate开发人员)所解释的那样:

但是,如果您不满意这种情况在使用扩展持久化上下文时真的很烦人):Hibernate有一个补丁3.5.6_final 来改变这种行为。


I am trying to save an object using session.save as below:

beginTransaction();
sessionFactory.getCurrentSession().save(entity);
entity.setName("Entity " + Math.random());
commitTransaction();

The following sql are generated :

1)insert into entity
2)update set name =

Why should it generate separate update sql even when changes are flushed as late as possible ?

解决方案

It's the expected Hibernate behavior as explained by Gavin (one of the hibernate developers) here:

However, if you are unhappy with that (in my case it was really annoying when using extended persistence context): there is a patch for Hibernate 3.5.6_final here to change this behavior.

这篇关于额外的由Hibernate生成的sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 10:28
查看更多