-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate issuing additional SELECT
PostPosted: Wed Feb 04, 2009 5:46 pm 
Newbie

Joined: Wed Feb 04, 2009 5:27 pm
Posts: 1
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......
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2009 7:21 pm 
Regular
Regular

Joined: Fri Jan 30, 2009 10:10 am
Posts: 74
Location: London
"Favour composition over inheritance" is the phrase that comes to my mind.

When you extend a class, you are saying that your new class "is a" type of your original class.

When you come to query for all instances of the original class, Hibernate is looking down the inheritance hierarchy and finding your AnnualCertificationHistory objects - because they are instances of your AnnualCertification.


--
Stephen Souness


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.