I'm doing a read of base table which only returns one result. This is fine and exactly what I want. However, I have an additional history table that needs to be queried using a separate method all together, but still using the same service. This history table is almost an exact replica of the initial table except it adds two fields. I have two separate mapping files, each with there respective columns. As for the domain objects though, since the history table is almost the same, I made one contain all the entries for base table and the other to be a subclass and just contain the two extra fields as this saves on code duplication.
I went through and tested out the history method read by itself and it works fine. When going back to test the base table read, it fails. The reason being is that Hibernate queries the base table and returns the one result as I want, but when its done, it makes an additional read of the history table and adds those results to the initial read. Thus making my result not unique.
Is there a way to prevent Hibernate from issuing the additional SELECT of the history table?
Code:
BASE TABLE INFO
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.marketconduct.domain.AnnualCertification" table="annualcertification" lazy="false" schema="dbo" catalog="FieldSec">
<composite-id name="id" class="com.marketconduct.domain.AnnualCertificationId">
<key-property name="corpEmpIdCde" type="string">
<column name="corp_emp_id_cde" length="11" />
</key-property>
<key-property name="certYear" type="short">
<column name="cert_year" />
</key-property>
</composite-id>
<property name="firstNm" type="string" column="first_nm" length="20" not-null="true" />
<property name="lastNm" type="string" column="last_nm" length="20" not-null="true" />
<property name="emplNm" type="string" column="empl_nm" length="40" not-null="true" />
<property name="agyCde" type="string" column="AGY_CDE" length="4" not-null="true" />
<property name="frCde" type="string" column="FR_CDE" length="8" not-null="true" />
<property name="fileNm" type="string" column="file_nm" length="25" not-null="true" />
<property name="fileData" type="binary" column="FILE_DATA" />
<property name="certDate" type="timestamp" column="cert_dt" length="23" not-null="true" />
<property name="supvNoteTxt" type="string" column="supv_note_txt" length="2000" />
<property name="createDateTimeStamp" column="cret_tmsp" type="timestamp" length="23" not-null="true"/>
<property name="lastUpdateDateTimeStamp" column="lst_updt_tmsp" type="timestamp" length="23" not-null="true"/>
<property name="createUserId" column="cret_user_id" type="string" length="128" not-null="true"/>
<property name="lastUpdateUserId" column="lst_updt_user_id" type="string" length="128" not-null="true"/>
</class>
</hibernate-mapping>
public class AnnualCertification {
private AnnualCertificationId id;
private String firstNm;
private String lastNm;
private String emplNm;
private String agyCde;
private String frCde;
private String fileNm;
private byte[] fileData;
private Date certDate;
private String supvNoteTxt;
private Date createDateTimeStamp;
private Date lastUpdateDateTimeStamp;
private String createUserId;
private String lastUpdateUserId;
.....getters and setters ....
}
HISTORY TABLE INFO
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping >
<class name="com.marketconduct.domain.history.AnnualCertificationHistory" table="annualcertification_hst" lazy="false" schema="dbo" catalog="FieldSec">
<composite-id name="idHist" class="com.marketconduct.domain.history.AnnualCertificationHistoryId">
<key-property name="corpEmpIdCde" type="string">
<column name="corp_emp_id_cde" length="11" />
</key-property>
<key-property name="certYear" type="short">
<column name="cert_year" />
</key-property>
<key-property name="processDateTime" type="timestamp">
<column name="proc_dt_tmsp" />
</key-property>
</composite-id>
<property name="firstNm" type="string" column="first_nm" length="20" not-null="true" />
<property name="lastNm" type="string" column="last_nm" length="20" not-null="true" />
<property name="emplNm" type="string" column="empl_nm" length="40" not-null="true" />
<property name="agyCde" type="string" column="AGY_CDE" length="4" not-null="true" />
<property name="frCde" type="string" column="FR_CDE" length="8" not-null="true" />
<property name="fileNm" type="string" column="file_nm" length="25" not-null="true" />
<property name="supvNoteTxt" type="string" column="supv_note_txt" length="2000" />
<property name="createDateTimeStamp" column="cret_tmsp" type="timestamp" length="23" not-null="true"/>
<property name="lastUpdateDateTimeStamp" column="lst_updt_tmsp" type="timestamp" length="23" not-null="true"/>
<property name="createUserId" column="cret_user_id" type="string" length="128" not-null="true"/>
<property name="lastUpdateUserId" column="lst_updt_user_id" type="string" length="128" not-null="true"/>
<property name="sourceOperSwitchCode" column="src_oper_sw_cde" type="string" length="1" not-null="true"/>
</class>
</hibernate-mapping>
public class AnnualCertificationHistory extends AnnualCertification
{
private String sourceOperSwitchCode;
private AnnualCertificationHistoryId idHist;
.......getters and setters......
}