Hibernate和Spring配合使用的一个问题

最近的一个项目使用Hibernate3和Spring,DAO都是继承自
org.springframework.orm.hibernate3.support.HibernateDaoSupport,提供了一个
BaseDAO,提供了常用的get,getAll,insert,delete以及update方法,其它的DAO都不用关心这些操作了,但是在使用的
时候有一个问题,就是有时候会出现Illegal attempt to associate a collection with two open sessions的异常,但是在取得对象后使用session.close()也不行,会出现另外的一个异常session is not open or is closed,后来上网查了以下,原来是我的update方法有问题,原来就是getHibernateTemplate().update(object),修改为getHibernateTemplate().merge(object)问题解决。

2005.11.23更新:
按照API文档:
merge(Object entity)

          Copy the state of the given object onto the persistent object
with the same identifier.

update(Object entity)

          Update the given persistent instance,
associating it with the current Hibernate Session.
问题的根源可能在于要更新的那个对象是有一个关联集合的。


作者: Cherami
原载: Hibernate和Spring配合使用的一个问题
版权所有。转载时必须以链接形式注明作者和原始出处及本声明。

日志评价

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (暂无评价) --点击星星直接投票
Loading ... Loading ...


相关日志



随机日志



添加到网摘

[del.icio.us]  [新浪 VIVI]  [365key]  [YouNote]  [博采中心]  [Poco]  [SOHU狐摘]  [天极网摘]  [和讯网摘]
喜欢这个插件?

当前日志信息