`

修改带<any>关联的对象报collection was not processed by flush

阅读更多
     今天修改带<any>关联的对象报错:org.hibernate.AssertionFailure:collection was not processed by flush()!涉及到了3个对象,一个企业,一个产品,一个收藏,其中收藏里通过<any>关联着企业和产品,是对产品和企业的收藏,映射文件如下:
-----------------------TPrettyFavorite.htm.xml---------------------
<class name="TPrettyFavorite" table="cn_list_TPrettyFavorite">
  <id name="id" type="integer" column="id">
    <generator class="native"/>
  </id>
  <property name="name" column="name" type="string" not-null="false" length="255"/>
  <property name="content" column="content" type="text"/>
  <any name="favorite" meta-type="string" id-type="integer" cascade="none" lazy="false">
    <meta-value value="product" class="cn.product.TPrettyProduct"/>
    <meta-value value="enterprise" class="cn.enterprise.TPrettyEnterprise"/>
    <column name="favoriteType"/>
    <column name="favoriteId"/>
  </any>
</class>

TPrettyProduct和TPrettyEnterpirse的映射文件从略。
下面是处理修改TPrettyFavorite对象的代码:
//temp是从页面传递过来的TPrettyFavorite对象
IPrettyFavorite temp = (IPrettyFavorite) this.getTableObject();
//article是从数据库里根据temp的id load出来的TPrettyFavorite对象
IPrettyFavorite article = (IPrettyFavorite) this.getCurrentTemplate.load(TPrettyFavorite.class,new Integer(temp.getId()));
article.setContent(temp.getContent());
this.getCurrentTemplate().setFlushMode(HibernateTemplate.FLUSH_ALWAYS);
this.getCurrentTemplate().saveOrUpdate(article);
this.getCurrentTemplate().flush();
this.getCurrentTemplate().evict(article);

下面是日志里打出来的信息:
2007-09-03 18:53:52,781 ERROR [org.hibernate.AssertionFailure] - <an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)>
org.hibernate.AssertionFailure: collection was not processed by flush()
at org.hibernate.engine.CollectionEntry.postFlush(CollectionEntry.java:144)
at org.hibernate.event.def.AbstractFlushingEventListener.postFlush(AbstractFlushingEventListener.java:305)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:28)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:815)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
at org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:813)
分享到:
评论
4 楼 crazyasp 2007-09-04  
3 楼 DavyLee 2007-09-04  
hibernate的官方网站说这个是一个bug,是在更新any的关联的时候的问题,在3.2版本已经修正了!
2 楼 DavyLee 2007-09-04  
这种问题太幼稚了!
1 楼 DavyLee 2007-09-04  
org.hibernate.AssertionFailure: collection was not processed by flush
At work, we ran into this Hibernate problem and it took us forever to figure out. He is a short description of the problem and the what caused it for us.

Credit for finding and resolving this goes to Rick B. and Linda R.

org.hibernate.AssertionFailure: collection was not processed by flush() ERROR [main] hibernate.AssertionFailure - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session) org.hibernate.AssertionFailure: collection was not processed by flush()

We discovered that custom code was causing Hibernate to explode the object graph too late in the flush execution for the new items to be processed or ignored. Be on the watch for custom implementations of methods common to all objects such as equals(), hashCode() and comparators.

Background: We had implemented a comparator for sorting purposes. During the flush execution, Hibernate called the compare method on our comparator. A side-effect of the comparator processing caused Hibernate to instantiate additional CollectionEntry objects. Typically, for objects instantiated during the flush, Hibernate marks them so that they are ignored during the processing. These objects which were created due to our comparator processing were created too late so Hibernate was not able to mark to be ignored. During postFlush it saw the objects in the collection but since they were not flagged as processed, nor flagged to be ignored the exception was thrown. The expected persistence was working correctly, however this exception was being thrown on numerous test cases.

We resolved the problem by testing for object identity (obj1 == obj2) at the beginning of the compare method. By doing this first and exiting when equal, the side-effect of lazy loading child objects is avoided in the comparator, which keeps Hibernate from instantiating unnecessary CollectionEntry objects for them. In general, following this best practice with comparators will ensure better performance as well (Refer to Effective Java chapter 3.)

相关推荐

    hibernate 教程

    动态关联对象获取(Dynamic association fetching)&lt;br&gt;12.6. 根据示例查询(Example queries)&lt;br&gt;13. 原生SQL查询&lt;br&gt;13.1. 创建一个基于SQL的Query&lt;br&gt;13.2. 别名和属性引用&lt;br&gt;13.3. 为SQL查询命名&lt;br&gt;14. 性能...

    hibernate

    动态关联对象获取(Dynamic association fetching)&lt;br&gt;12.6. 根据示例查询(Example queries)&lt;br&gt;13. 原生SQL查询&lt;br&gt;13.1. 创建一个基于SQL的Query&lt;br&gt;13.2. 别名和属性引用&lt;br&gt;13.3. 为SQL查询命名&lt;br&gt;14. 性能...

    js效果页面实例及说明文档包html版

    绝对的经典javascript收藏 包含了各个种类的js校验实例&lt;br&gt;web开发绝妙帮手&lt;br&gt;&lt;br&gt;javascript收藏 &lt;br&gt;1.页面校验 &lt;br&gt;1.文本框约束输入 &lt;br&gt;2.表单校验工具库 &lt;br&gt;3.文本框部分内容不让改变 &lt;br&gt;2.下拉框类 &lt;br&gt;...

    MYSQL

    &lt;br&gt;7.4.7 类型转换运算符 &lt;br&gt;7.4.8 控制流函数 &lt;br&gt;7.4.9 数学函数 &lt;br&gt;7.4.10 字符串函数 &lt;br&gt;7.4.11 日期和时间函数 &lt;br&gt;7.4.12 其他函数 &lt;br&gt;7.4.13 与GROUP BY子句一起使用的函数 &lt;br&gt;7.5 CREATE DATABASE ...

    基于HTML爬虫的豆瓣小组API(Python版本).zip

    - req &lt;url&gt; &lt;method&gt; &lt;params&gt; &lt;data&gt; &lt;auth&gt; - toJSON - to_xml &lt;content&gt; &lt;kwargs&gt; - use &lt;cookies&gt; - xml &lt;url&gt; &lt;method&gt; &lt;params&gt; &lt;data&gt; - group - group add_comment &lt;topic_id&gt; &lt;content&gt; &lt;reply_id...

    aspnet对文件,文件夹以及xml的操作

    &lt;br&gt; file.Flush();&lt;br&gt; file.Close();&lt;br&gt; fso.Close(); &lt;br&gt; string path1 = Server.MapPath("xiaofenga.txt");&lt;br&gt; StreamReader sr = new StreamReader(path1);&lt;br&gt; //读取所有内容&lt;br&gt; Response.Write(sr....

    memcached常用指令.txt

    - `flush_all [&lt;time&gt;] [noreply]`:清空所有缓存数据,可选的时间参数表示延迟执行的时间。 - `version`:显示memcached的版本信息。 - `verbosity &lt;level&gt; [noreply]`:设置日志记录级别。 - `quit`:退出当前的...

    org.apache.tools.zip解决解压乱码问题

    * 修改日期:&lt;br&gt; */ public class ZipUtil { /** * * 功能描述:压缩文件 &lt;br&gt; * 创建者:XXX &lt;br&gt; * 创建日期: 2015年5月7日 - 下午1:35:18&lt;br&gt; * 版本: V0.1 &lt;br&gt; * 修改者: &lt;br&gt; * 修改...

    html转pdfHTML导出PDF中文、ITEXT转HTML为PDF包括中文显示解决方案

    fontResolver.addFont(fontPath.toString(), BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); // 解决图片的相对路径问题 // renderer.getSharedContext().setBaseURL("file:/F:/teste/html/"); renderer....

    hivesql语句练习

    &lt;description&gt;JDBC connect string for a JDBC metastore&lt;/description&gt; &lt;/property&gt; &lt;property&gt; &lt;name&gt;javax.jdo.option.ConnectionDriverName&lt;/name&gt; &lt;value&gt;com.mysql.jdbc.Driver&lt;/value&gt; &lt;description&gt;...

    centos7中hive的安装和使用

    &lt;name&gt;javax.jdo.option.ConnectionDriverName&lt;/name&gt; &lt;value&gt;com.mysql.jdbc.Driver&lt;/value&gt; &lt;/property&gt; &lt;property&gt; &lt;name&gt;javax.jdo.option.ConnectionUserName&lt;/name&gt; &lt;value&gt;root&lt;/value&gt; &lt;/property&gt; ...

    MySQL中文参考手册.chm

    &lt;br/&gt;8.4.4.3 选择特定列 &lt;br/&gt;8.4.4.4 排序行 &lt;br/&gt;8.4.4.5 日期计算 &lt;br/&gt;8.4.4.6 NULL值操作 &lt;br/&gt;8.4.4.7 模式匹配 &lt;br/&gt;8.4.4.8 行计数 &lt;br/&gt;8.4.5 使用多个数据库表 &lt;br/&gt;8.5 获得数据库和表的信息 &lt;br/&gt;8.6 ...

    简单的memcache命令

    add &lt;key&gt; &lt;flag&gt; &lt;expiration_time_in_seconds&gt; &lt;byte_count_of_value&gt; &lt;value&gt; ``` **解释**: - `&lt;key&gt;`:键名,用于标识缓存中的数据。 - `&lt;flag&gt;`:标志位,通常用于表示数据的类型或附加信息,默认为0。 - `...

    事业单位公事审批系统

    &lt;jsp:include flush="true" page="head.jsp"/&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;form name="form1" method="post" action="DepAddSave.jsp" onSubmit="return check();"&gt; &lt;table width="500" height="104" border="1" ...

    Ubuntu下安装hive数据库

    &lt;description&gt;Username to use against metastore database&lt;/description&gt; &lt;/property&gt; &lt;property&gt; &lt;name&gt;javax.jdo.option.ConnectionPassword&lt;/name&gt; &lt;value&gt;hive&lt;/value&gt; &lt;description&gt;Password to use ...

    导出Excel到自定义位置

    resp.Write("&lt;table class='table'&gt;&lt;tr&gt;&lt;th&gt;" +"文件标题"+ "&lt;/th&gt;&lt;th&gt;" + "档案类别" + "&lt;/th&gt;&lt;th&gt;" +"发文日期" + "&lt;/th&gt;&lt;th&gt;" +"文件链接" + "&lt;/th&gt;&lt;th&gt;" +"备注" + "&lt;/th&gt;&lt;/tr&gt;"); //VideoList = (List...

    Java实现Html转PDF

    &lt;artifactId&gt;spring-boot-starter-freemarker&lt;/artifactId&gt; &lt;/dependency&gt; &lt;!-- html 转 pdf --&gt; &lt;dependency&gt; &lt;groupId&gt;com.itextpdf&lt;/groupId&gt; &lt;artifactId&gt;itextpdf&lt;/artifactId&gt; &lt;version&gt;5.5.11&lt;/...

    Memcache常用命令.pdf

    - `replace &lt;key&gt; &lt;flags&gt; &lt;expiration&gt; &lt;bytes&gt; [value]`: 替换已有键的值,如果键不存在则失败。 - **追加数据**: - `append &lt;key&gt; &lt;flags&gt; &lt;expiration&gt; &lt;bytes&gt; [value]`: 追加数据到已存在的键后。 - **前置...

    hive的安装.pdf

    - 允许 root 用户远程登录:`mysql &gt; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;` - 强制应用更改:`mysql &gt; FLUSH PRIVILEGES;` 2. **配置 Hive**: - **修改 `...

    itext加载velocity生成PDF

    &lt;version&gt;5.x.x&lt;/version&gt; &lt;!-- 使用合适的版本 --&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.velocity&lt;/groupId&gt; &lt;artifactId&gt;velocity&lt;/artifactId&gt; &lt;version&gt;1.x.x&lt;/version&gt; &lt;!-- 使用合适的版本 ...

Global site tag (gtag.js) - Google Analytics