As shown below, I have a class Foo with a data member of type Bar. The data member, bar, is mapped as "Serializable". Hence during a hibernate commit to the database its Serialization code is called (readExternal and writeExternal).
During performance testing we noticed that each call to commit an instance of "Foo" calls the Serialization code for the "bar" data member 4 times AND the De-Serialization code 1 time. The sequence is as follows:
For each bar:
Serialize bar;
DeSerialize bar;
Serialize bar;
Serialize bar;
Serialize bar
The data member "bar" (of type Bar) is stored as a Blob in the database. This object can get to be quite large. Hence the multiple Serializations and De-Serializations add up very fast.
Does anyone know why this is done this way and if there's a way to avoid the multiple calls?
Thanks
Zac George
Hibernate version: 3
// Mapping file
<hibernate-mapping
package="com.makesys.common.utilities.config">
<class name="Foo" table="FOO">
...
<property name="bar"
column="bar"
type="serializable"
not-null="false"
access="field"/>
</class>
// class Foo
public class Foo
{
private Bar bar; // Bar implements Serializable
...
}
//class Bar
public class Bar
{
public void writeExternal(ObjectOutput out)
{
... // code to serialize bar
}
public void readExternal(ObjectInput in)
{
... // code to de-serialize bar
}
}
|