Hello. The developers in out group is running into an interesting situation. When we try to persist an entity object (it's called ClaimCase on our end) using the Session.persist(entityObject) function, we discover that hibernate outputs the follow statements:
Hibernate: select CIW3.hibernate_sequence.nextval from dual
Hibernate: insert into CIW3.SICCIW_CLAIMCASE (OBJ_VERSION, CREATE_TIMESTAMP, GRP_PROD_TERM_DT, GRP_TERM_DT, GRP_NM, AMEND1_DT, AMEND2_DT, RENEWAL_DT, GRP_SALES_OFFICE_ID, GRP_ID, ISSUE_ST_CD, POL_PREM_CONT, CONTRIBUTORY, ASO_TYPE, ASO_FLAG, CLM_SRCH_CMNT, ADMIN_UNIT, TAX_UNIT, CLM_NUM, CO_RESP_CD, OFFC_LOC, RECD_DT, INTK_RECD_DT, SOURCE, INTK_CLM_STAT, INTK_CLM_RSN_CD, ASSIGN_DT, SECTOR_CD, LAST_CHG_DATE, LAST_CHG_USER, CASE_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: update CIW3.SICCIW_CLAIMCASE set OBJ_VERSION=?, CREATE_TIMESTAMP=?, GRP_PROD_TERM_DT=?, GRP_TERM_DT=?, GRP_NM=?, AMEND1_DT=?, AMEND2_DT=?, RENEWAL_DT=?, GRP_SALES_OFFICE_ID=?, GRP_ID=?, ISSUE_ST_CD=?, POL_PREM_CONT=?, CONTRIBUTORY=?, ASO_TYPE=?, ASO_FLAG=?, CLM_SRCH_CMNT=?, ADMIN_UNIT=?, TAX_UNIT=?, CLM_NUM=?, CO_RESP_CD=?, OFFC_LOC=?, RECD_DT=?, INTK_RECD_DT=?, SOURCE=?, INTK_CLM_STAT=?, INTK_CLM_RSN_CD=?, ASSIGN_DT=?, SECTOR_CD=?, LAST_CHG_DATE=?, LAST_CHG_USER=? where CASE_ID=? and OBJ_VERSION=?
Hibernate: update CIW3.SICCIW_CLAIMCASE set OBJ_VERSION=?, CREATE_TIMESTAMP=?, GRP_PROD_TERM_DT=?, GRP_TERM_DT=?, GRP_NM=?, AMEND1_DT=?, AMEND2_DT=?, RENEWAL_DT=?, GRP_SALES_OFFICE_ID=?, GRP_ID=?, ISSUE_ST_CD=?, POL_PREM_CONT=?, CONTRIBUTORY=?, ASO_TYPE=?, ASO_FLAG=?, CLM_SRCH_CMNT=?, ADMIN_UNIT=?, TAX_UNIT=?, CLM_NUM=?, CO_RESP_CD=?, OFFC_LOC=?, RECD_DT=?, INTK_RECD_DT=?, SOURCE=?, INTK_CLM_STAT=?, INTK_CLM_RSN_CD=?, ASSIGN_DT=?, SECTOR_CD=?, LAST_CHG_DATE=?, LAST_CHG_USER=? where CASE_ID=? and OBJ_VERSION=?
And here is the code:
// Get the ClaimIntakeDAO from Spring-framework
ClaimIntakeDAO claimIntakeDao = (ClaimIntakeDAO)context.getBean("ClaimIntakeFactory");
// Allocate/initialize the ClaimCase
ClaimCase claimCase = new ClaimCase();
claimCase.setCreatedTimestamp(date);
ClaimCase persistCase = claimIntakeDao.save(claimCase);
Here is the code for the claimIntakeDao.save function
public ClaimCase save( ClaimCase claimCase ) {
try {
Session session = getSession();
// Associate claim case hierarchy to session for persistence.
Date createDate = claimCase.getCreatedTimestamp();
if ( createDate == null ) {
claimCase.setCreatedTimestamp( new Date());
}
if (claimCase.getCiwId() == null){
session.persist(claimCase); (It's new, we are executing this line.)
}
else {
session.saveOrUpdate(claimCase); (If this is called, we get two update statements.)
}
session.flush();
}
catch(HibernateException ex) { // catch hibernate exception
throw new DaoHibernateException(HIBERNATE_ERROR, ex);
}
return claimCase;
}
I believe the statements are printed out when the session.flush() line is executed.
Initially, we were using versioning (the <version> tag, which you will see in the hibernate mapping below) and we also use the interceptor and override the onFlushDirty and onSave functions in order to put tracking fields like last modified user and last modified date. We thought may be the interceptor or the versioning was the issue and we remove them from our code. It did not make a difference.
Also tried to set the select-before-update attribute to true and it has no effect.
The only other item I can think of is the relationship amoung the entity objects themselves. However in the example above only the topmost entity object is created, so I do not think that's the reason. I am wondering if anyone has experience anything like this and have a solution? Any help is very much appreciated.
Finally, here is the hibernate mapping. I have deleted some <property> tag because the mapping is too long to post. But the helow should give you a good idea on what we are trying to do and the relationship amoung the entity objects.
<?xml version="1.0"?>
<!-- Created with Liquid XML Studio - FREE Community Edition 7.1.4.1284 (
http://www.liquid-technologies.com) -->
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"[]>
<hibernate-mapping package="com.xxx.xxx.xxx.dao.impl">
<class name="Party" abstract="true" table="SICCIW_PARTY" optimistic-lock="version" polymorphism="implicit">
<meta attribute="implements">com.xxx.xxx.xxx.dao.SICAuditable</meta>
<id name="partyId" type="integer">
<meta attribute="scope_set">protected</meta>
<meta attribute="use-in-tostring">true</meta>
<column name="PARTY_ID" not-null="true">
</column>
<generator class="sequence">
</generator>
</id>
<discriminator column="PARTY_TYPE" type="string" />
<version name="version" type="integer" access="field" column="OBJ_VERSION" unsaved-value="negative" />
<property name="createdTimestamp" column="CREATE_TIMESTAMP" type="com.ipd.common.dao.HibernateUTC$TimestampType" not-null="true">
<meta attribute="use-in-equals">true</meta>
</property>
<!-- Deleted Properties --->
<subclass name="Caller" discriminator-value="Caller">
<property name="callTypeCreate" type="java.lang.Boolean" column="CLMNT_CALL_CREATE_FLG" not-null="false" />
<property name="callTypeStatus" type="java.lang.Boolean" column="CLMNT_CALL_STATUS_FLG" not-null="false" />
<property name="callTypeUpdate" type="java.lang.Boolean" column="CLMNT_CALL_UPDATE_FLG" not-null="false" />
<property name="relationToEmployee" type="string" column="EMP_RELATION" length="35" not-null="false" />
</subclass>
</class>
<subclass abstract="true" name="PartyProfile" extends="Party">
<property name="address1" type="string" column="ADDR1" length="55" not-null="false" />
<!-- Deleted Properties --->
<many-to-one name="claimCase" class="ClaimCase" column="CASE_ID" foreign-key="PRTY_CLMCASE_FK" />
<subclass name="Claimant" discriminator-value="Claimant">
<property name="accidentDate" type="com.ipd.common.dao.HibernateUTC$TimestampType" column="ACCT_DT" not-null="false" />
<property name="ceaseWorkDate" type="com.ipd.common.dao.HibernateUTC$TimestampType" column="CEASE_WORK_DT" not-null="false" />
<!-- deleted properties --->
</subclass>
<subclass name="Employer" discriminator-value="Employer">
<property name="appropRtwProgramFlag" type="java.lang.Boolean" column="APPROP_RTW_PRGM_FLG" not-null="false" />
<property name="compensationType" type="string" column="COMP_TYP" length="55" not-null="false" />
<!-- deleted properties --->
</subclass>
<subclass name="EmployerClaimant" discriminator-value="EmployerClaimant">
<property name="employeeId" type="string" column="EMP_ID" length="20" not-null="false" />
<property name="policyNumber" type="string" column="PLCY_NBR" length="11" not-null="false" />
<!-- deleted properties --->
</subclass>
<subclass name="EmployerHR" discriminator-value="EmployerHR">
<property name="fullName" type="string" column="FULL_NM" length="180" not-null="false" />
</subclass>
<subclass name="ClaimantHR" discriminator-value="ClaimantHR">
<property name="fullName" type="string" column="FULL_NM" length="180" not-null="false" />
</subclass>
<subclass name="WCCarrier" discriminator-value="WCCarrier">
<property name="fullName" type="string" column="FULL_NM" length="180" not-null="false" />
</subclass>
<subclass name="Physician" discriminator-value="Physician">
<property name="physicianSpecialty" type="string" column="PHYS_SPEC" length="60" not-null="false" />
<property name="displayOrder" type="integer" column="SORT_KEY" not-null="false" />
</subclass>
</subclass>
<class name="IntakeActivity" table="SICCIW_CALLER_ACTIVITY" optimistic-lock="version" polymorphism="implicit">
<id name="activityId" type="integer">
<meta attribute="scope_set">protected</meta>
<meta attribute="use-in-tostring">true</meta>
<column name="ACTIVITY_ID" not-null="true">
</column>
<generator class="sequence">
</generator>
</id>
<version name="version" type="integer" access="field" column="OBJ_VERSION" unsaved-value="negative">
</version>
<property name="createdTimestamp" column="CREATE_TIMESTAMP" type="com.ipd.common.dao.HibernateUTC$TimestampType" not-null="true">
<meta attribute="use-in-equals">true</meta>
</property>
<property name="ulteraUserId" type="string" length="100" column="USER_ID" not-null="false" />
<many-to-one name="claimCase" class="ClaimCase" column="CASE_ID" not-null="true" foreign-key="INTAKE_ACTVTY_CLMCASE_FK" />
<many-to-one name="caller" class="Caller" column="PARTY_ID" lazy="false" cascade="all" not-null="true" unique="true" foreign-key="INTAKE_ACTVTY_PRTY_FK" />
</class>
<class name="Requirement" table="SICCIW_REQUIREMENT" optimistic-lock="version">
<meta attribute="implements">com.xxx.xxx.xxx.dao.SICAuditable</meta>
<id name="requirementID" type="integer">
<meta attribute="scope_set">protected</meta>
<meta attribute="use-in-tostring">true</meta>
<column name="REQ_ID" not-null="true">
</column>
<generator class="sequence">
</generator>
</id>
<version name="version" type="integer" access="field" column="OBJ_VERSION" unsaved-value="negative" />
<property name="configID" type="integer" column="REQ_CFG_ID" not-null="true">
<meta attribute="use-in-equals">true</meta>
</property>
<property name="name" type="string" length="200" column="REQ_NM" not-null="true" />
<!-- deleted properties --->
<property name="createdTimestamp" column="CREATE_TIMESTAMP" type="com.ipd.common.dao.HibernateUTC$TimestampType" not-null="true">
<meta attribute="use-in-equals">true</meta>
</property>
<many-to-one name="claimCase" class="ClaimCase" column="CASE_ID" not-null="true" foreign-key="REQUIREMENT_CLMCASE_FK" />
<set name="activities" inverse="true" cascade="all, delete-orphan" lazy="false" order-by="SORT_KEY asc">
<key column="REQ_ID" />
<one-to-many class="Activity" />
</set>
</class>
<class name="Activity" table="SICCIW_ACTIVITY" optimistic-lock="version">
<meta attribute="implements">com.xxx.xxx.xxx.dao.SICAuditable</meta>
<id name="activityID" type="integer">
<meta attribute="scope_set">protected</meta>
<meta attribute="use-in-tostring">true</meta>
<column name="ACTIVITY_ID" not-null="true">
</column>
<generator class="sequence">
</generator>
</id>
<version name="version" type="integer" access="field" column="OBJ_VERSION" unsaved-value="negative" />
<property name="createdTimestamp" column="CREATE_TIMESTAMP" type="com.ipd.common.dao.HibernateUTC$TimestampType" not-null="true">
<meta attribute="use-in-equals">true</meta>
</property>
<property name="dependencyReqID" type="integer" column="DEP_REQ_ID" not-null="true" />
<property name="configID" type="integer" column="ACT_CFG_ID" not-null="true">
<meta attribute="use-in-equals">true</meta>
</property>
<!-- deleted properties --->
<many-to-one name="requirement" class="Requirement" column="REQ_ID" not-null="true" foreign-key="ACTIVITY_REQ_FK" />
</class>
<class name="ClaimCase" table="SICCIW_CLAIMCASE" optimistic-lock="version">
<meta attribute="implements">com.xxx.xxx.xxx.dao.SICAuditable</meta>
<meta attribute="implement-equals">true</meta>
<meta attribute="generated-class">com.standard.ulterap8.claimintake.dao.impl.ClaimCaseBase</meta>
<meta attribute="scope-field">protected</meta>
<id name="ciwId" type="integer">
<meta attribute="scope_set">protected</meta>
<meta attribute="use-in-tostring">true</meta>
<column name="CASE_ID" not-null="true">
</column>
<generator class="sequence" />
</id>
<version name="version" access="field" column="OBJ_VERSION" type="integer">
</version>
<property name="createdTimestamp" type="com.ipd.common.dao.HibernateUTC$TimestampType" column="CREATE_TIMESTAMP" not-null="true">
<meta attribute="use-in-equals">true</meta>
</property>
<!-- deleted properties --->
<property name="sectorCode" type="string" length="7" column="SECTOR_CD" not-null="false" />
<one-to-one name="insuredInfo" class="InsuredInfo" property-ref="claimCase" cascade="all" />
<set name="intakeActivities" inverse="true" cascade="all, delete-orphan" lazy="false" order-by="CREATE_TIMESTAMP asc">
<key column="CASE_ID" />
<one-to-many class="IntakeActivity" />
</set>
<set name="parties" inverse="true" cascade="all, delete-orphan" lazy="false">
<meta attribute="scope_set">protected</meta>
<key column="CASE_ID" />
<one-to-many class="PartyProfile" />
</set>
<set name="requirements" inverse="true" cascade="all, delete-orphan" lazy="false" order-by="SORT_KEY">
<key column="CASE_ID" />
<one-to-many class="Requirement" />
</set>
<property name="lastChangeDate" type="com.ipd.common.dao.HibernateUTC$TimestampType" column="LAST_CHG_DATE" not-null="false" />
<property name="lastChangeUser" type="string" length="100" column="LAST_CHG_USER" not-null="false" />
</class>
<class name="InsuredInfo" table="SICCIW_INSURED_INFO" optimistic-lock="version">
<id name="infoID" type="integer">
<meta attribute="scope_set">protected</meta>
<meta attribute="use-in-tostring">true</meta>
<column name="INFO_ID" not-null="true">
</column>
<generator class="sequence" />
</id>
<property name="unionName" type="string" length="95" column="UNION_NM" not-null="false" />
<!-- deleted properties --->
<property name="rehireDate" type="com.ipd.common.dao.HibernateUTC$TimestampType" column="REHIRE_DT" not-null="false" />
<many-to-one name="claimCase" class="ClaimCase" column="CASE_ID" unique="true" foreign-key="INSINFO_CLMCASE_FK" />
<set name="employmentRptCategories" inverse="true" cascade="all, delete-orphan" lazy="false" order-by="NAME">
<key column="INFO_ID" />
<one-to-many class="EmploymentContext" />
</set>
<set name="employmentProducts" inverse="true" cascade="all, delete-orphan" lazy="false">
<key column="INFO_ID" />
<one-to-many class="EmploymentProduct" />
</set>
<set name="earnings" inverse="true" cascade="all, delete-orphan" lazy="false">
<key column="INFO_ID" />
<one-to-many class="Earning" />
</set>
</class>
<class name="EmploymentContext" table="SICCIW_EMP_CONTEXT" optimistic-lock="version">
<id name="empContextID" type="integer">
<meta attribute="scope_set">protected</meta>
<meta attribute="use-in-tostring">true</meta>
<column name="EMP_CNTXT_ID" not-null="true">
</column>
<generator class="sequence">
</generator>
</id>
<property name="name" type="string" length="50" column="NAME" not-null="false">
<meta attribute="use-in-equals">true</meta>
</property>
<property name="value" type="string" column="VALUE" not-null="false" />
<many-to-one name="insuredInfo" class="InsuredInfo" column="INFO_ID" not-null="true" foreign-key="CONTEXT_INSURED_FK" />
</class>
<class name="EmploymentProduct" table="SICCIW_COVERAGE" optimistic-lock="version">
<id name="prodID" type="integer">
<meta attribute="scope_set">protected</meta>
<meta attribute="use-in-tostring">true</meta>
<column name="PROD_ID" not-null="true">
</column>
<generator class="sequence">
</generator>
</id>
<property name="name" type="string" length="50" column="NAME" not-null="false">
<meta attribute="use-in-equals">true</meta>
</property>
<property name="effectiveDate" type="com.ipd.common.dao.HibernateUTC$TimestampType" column="EFF_DATE" not-null="false" />
<property name="electBenAmt" type="java.lang.Float" precision="10" scale="2" column="ELECTED_BEN_AMT" not-null="false" />
<many-to-one name="insuredInfo" class="InsuredInfo" column="INFO_ID" not-null="true" foreign-key="COVERAGE_INSURED_FK" />
</class>
<class name="Earning" table="SICCIW_EARNING" optimistic-lock="version">
<id name="earningID" type="integer">
<meta attribute="scope_set">protected</meta>
<meta attribute="use-in-tostring">true</meta>
<column name="EARNING_ID" not-null="true">
</column>
<generator class="sequence">
</generator>
</id>
<property name="frequency" type="string" length="70" column="FREQUENCY" not-null="false" />
<property name="amount" type="java.lang.Float" precision="10" scale="2" column="AMOUNT" not-null="false" />
<property name="type" type="string" length="25" column="TYPE" not-null="false">
<meta attribute="use-in-equals">true</meta>
</property>
<property name="earnChgDate" type="com.ipd.common.dao.HibernateUTC$TimestampType" column="EARN_CHG_DT" not-null="false" />
<many-to-one name="insuredInfo" class="InsuredInfo" column="INFO_ID" not-null="true" foreign-key="EARNING_INSURED_FK" />
</class>
</hibernate-mapping>