I'm running into something strange revolving around the usage of a
serialized collection (or perhpas not so strange, if my understanding of
serialized objects is not adequate...).
As the mapping file below illustrates, I have a map whose values are actually
serialized collections themselves. Please don't ask what the motivation of
the original author of this mapping was... I don't know. The object is, in
usage, really just a static collection of informaiton - meaning, it's data is not
mutated.
The problem is arising that whenever this object is retrieved from Hibernate,
and saveOrUpdate() is called on an object that references this object, the
version is being incremented on this object even though none of it's info has
changed.
I traced the call back to an insert on the serialized value (see the 'generated
SQL' section below). The values of the serialized object are the same when
the object is hydrating and when it is being re-inserted during the
saveOrUpdate.
So, my question is if anyone knows why this is happening (is this 'correct'
behavior?), and if so, what can be done to prevent the version increment.
Cheers!
Hibernate version: 3.1
Name and version of the database you are using: Postgres 8
Mapping documents:
Code:
<joined-subclass name="SuperClassImpl" extends="BaseClass" table="supers" dynamic-update="true">
<key column="cid"/>
<property name="profile" access="field" column="profile" type="string"/>
<map name="attributeMap" access="field" cascade="all" table="super_attribute_map">
<key column="cid"/>
<map-key column="name" type="string"/>
<element column="myAttributes" type="serializable"/>
</map>
</joined-subclass>
The generated SQL (show_sql=true):
When the object is Hydrating :
Code:
Hibernate: select attributem0_.cid as cid0_, attributem0_.myAttributes as serviceA2_0_, attributem0_.name as name0_ from super_attribute_map attributem0_ where attributem0_.cid=?
15:11:39,793 DEBUG StringType:80 --- binding 'ff8080810f348318010f3483394d0004' to parameter: 1
15:11:39,897 DEBUG StringType:122 --- returning 'ff8080810f348318010f3483394d0004' as column: cid0_
15:11:40,037 DEBUG SerializableType:122 --- returning '2c6d8085f3f28094eae1f6e1aef5f4e9ecaed0f2eff0e5f2f4e9e5f3b99250faf0b6be18828081cc8088e4e5e6e1f5ecf4f3f48096cceae1f6e1aff5f4e9ecafd0f2eff0e5f2f4e9e5f3bbf8f28093eae1f6e1aef5f4e9ecaec8e1f3e8f4e1e2ece5933b8fa5a1ca6438838082c6808aecefe1e4c6e1e3f4eff2c98089f4e8f2e5f3e8efece4f8f0bfc0808080808088f7888080808580808085f48088f5f3e5f2eee1ede5f48086f4e5ede2efeff4808ce4e1f4e1e2e1f3e5eee1ede5f48084f1e1e4e2f48088e8eff3f4eee1ede5f4808bb1b0aeb1b0aeb1b0aeb3b1f48088f0e1f3f3f7eff2e4f180fe8085f4808ce4e1f4e1e2e1f3e5f4f9f0e5f4808ad0eff3f4e7f2e5d3d1ccf8f0' as column: serviceA2_0_
15:11:40,047 DEBUG StringType:122 --- returning 'debug' as column: name0_
When saveOrUpdate is called:
Code:
Hibernate: update super_attribute_map set myAttributes=? where cid=? and name=?
15:12:29,755 DEBUG SerializableType:80 --- binding '2c6d8085f3f28094eae1f6e1aef5f4e9ecaed0f2eff0e5f2f4e9e5f3b99250faf0b6be18828081cc8088e4e5e6e1f5ecf4f3f48096cceae1f6e1aff5f4e9ecafd0f2eff0e5f2f4e9e5f3bbf8f28093eae1f6e1aef5f4e9ecaec8e1f3e8f4e1e2ece5933b8fa5a1ca6438838082c6808aecefe1e4c6e1e3f4eff2c98089f4e8f2e5f3e8efece4f8f0bfc0808080808088f7888080808580808085f48088f5f3e5f2eee1ede5f48086f4e5ede2efeff4808ce4e1f4e1e2e1f3e5eee1ede5f48084f1e1e4e2f48088e8eff3f4eee1ede5f4808bb1b0aeb1b0aeb1b0aeb3b1f48088f0e1f3f3f7eff2e4f180fe8085f4808ce4e1f4e1e2e1f3e5f4f9f0e5f4808ad0eff3f4e7f2e5d3d1ccf8f0' to parameter: 1
15:12:29,778 DEBUG StringType:80 --- binding 'ff8080810f348318010f3483394d0004' to parameter: 2
15:12:29,789 DEBUG StringType:80 --- binding 'debug' to parameter: 3