Hello all,
I'm not a Hibernate expert and cannot seem to resolve this issue. Here is the problem.
I have a three classes named Compdep, Empdep, and Funddep (mappings below) where Compdep is the top level parent with a one-to-many association to Empdep, Empdep has a one-to-many association to Funddep, and Compdep also has a one-to-many association to Funddep. In a stateless session bean (using WebSphere JTA), a Compdep is loaded along with its Empdeps and each Empdep loads its Funddeps. This set of objects is returned to the servlet container for display on a form, so they become detached. When the user saves their changes, my code passes the Compdep and all it's children and grandchildren to the session bean that performs a
Code:
session.update(compDep);
session.flush();
The problem is that the Compdep, all of its children Empdeps, and all of their children Funddeps are updated to the database regardless of whether they changed. If they are not dirty, I would prefer they not be updated to the database to reduce the transaction time and only update those children and grandchildren that are dirty. Is this possible?
I am using the a version identifier on Compdep and Empdep for concurrency (mapping files below). Debug output is below that. What am I missing? I tried setting the "optimistic-lock" option at the class level for Empdep and Funddep to "none", but it doesn't change the behavior.
Any help you can provide would be very much appreciated. Thank you in advance.
Code:
<hibernate-mapping>
<class name="com.faweb.entities.Compdep" table="COMPDEP">
<id name="compdepid" type="long">
<column name="COMPDEPID" />
<generator class="identity" />
</id>
<version name="version" type="java.lang.Integer" unsaved-value="null">
<column name="VERSION" />
</version>
<property name="submitted" type="true_false">
<column name="SUBMITTED" length="1" not-null="false" />
</property>
<property name="lastUpdate" type="timestamp" insert="false" update="false" generated="always">
<column name="LAST_UPDATE" length="26" />
</property>
<property name="dateVerified" type="timestamp">
<column name="DATE_VERIFIED" length="26" />
</property>
<set name="empdeps" inverse="true" fetch="join" cascade="all">
<key>
<column name="COMPDEPID" not-null="true" />
</key>
<one-to-many class="com.faweb.entities.Empdep" />
</set>
</class>
--------------------------
<class name="com.faweb.entities.Empdep" table="EMPDEP" optimistic-lock="none">
<id name="empdepid" type="long">
<column name="EMPDEPID" />
<generator class="identity" />
</id>
<version name="version" type="java.lang.Integer" unsaved-value="null">
<column name="VERSION" />
</version>
<many-to-one name="compdep" class="com.faweb.entities.Compdep" fetch="select">
<column name="COMPDEPID" not-null="true" />
</many-to-one>
<property name="fiscaldate" type="int">
<column name="FISCALDATE" not-null="true" />
</property>
<property name="lastUpdate" type="timestamp" insert="false" update="false" generated="always">
<column name="LAST_UPDATE" length="26" />
</property>
<map name="funddeps" inverse="true" fetch="join" lazy="true" cascade="all" optimistic-lock="false">
<key column="EMPDEPID"/>
<map-key column="FUNDNUM"
type="int" />
<one-to-many class="com.faweb.entities.Funddep" />
</map>
</class>
----------------------
<class name="com.faweb.entities.Funddep" table="FUNDDEP" optimistic-lock="none">
<id name="funddepid" type="long">
<column name="FUNDDEPID" />
<generator class="identity" />
</id>
<version name="version" type="java.lang.Integer" unsaved-value="null">
<column name="VERSION" />
</version>
<many-to-one name="compdep" class="com.faweb.entities.Compdep" fetch="select">
<column name="COMPDEPID" />
</many-to-one>
<many-to-one name="empdep" class="com.faweb.entities.Empdep" lazy="false" fetch="select">
<column name="EMPDEPID" />
</many-to-one>
<property name="depamt" type="big_decimal">
<column name="DEPAMT" precision="11" />
</property>
<property name="lastUpdate" type="timestamp">
<column name="LAST_UPDATE" length="26" />
</property>
</class>
[b]
Output:[/b]
Code:
[4/22/10 21:46:47:266 CDT] 00000033 SystemOut O Hibernate:
update
faweb.COMPDEP
set
VERSION=?,
SUBMITTED=?,
DATE_VERIFIED=?
where
COMPDEPID=?
and VERSION=?
[4/22/10 21:46:47:266 CDT] 00000033 SystemOut O Hibernate:
select
compdep_.LAST_UPDATE as LAST29_97_
from
faweb.COMPDEP compdep_
where
compdep_.COMPDEPID=?
[4/22/10 21:46:47:281 CDT] 00000033 SystemOut O Hibernate:
update
faweb.EMPDEP
set
VERSION=?,
COMPDEPID=?,
FISCALDATE=?,
where
EMPDEPID=?
[4/22/10 21:46:47:281 CDT] 00000033 SystemOut O Hibernate:
select
empdep_.LAST_UPDATE as LAST19_108_
from
faweb.EMPDEP empdep_
where
empdep_.EMPDEPID=?
[4/22/10 21:46:47:281 CDT] 00000033 SystemOut O Hibernate:
update
faweb.FUNDDEP
set
VERSION=?,
COMPDEPID=?,
EMPDEPID=?,
DEPAMT=?,
LAST_UPDATE=?
where
FUNDDEPID=?
[4/22/10 21:46:47:281 CDT] 00000033 SystemOut O Hibernate:
update
faweb.FUNDDEP
set
VERSION=?,
COMPDEPID=?,
EMPDEPID=?,
DEPAMT=?,
LAST_UPDATE=?
where
FUNDDEPID=?