Does the WHERE clause that is declared in a class mapping get disregarded when that class is loaded in a collection?
Does it only apply when the class is loaded by id?
Hibernate version: 3.0.4
Mapping Documents
Class with WHERE clause:
<hibernate-mapping>
<class where="base_record_b = 'Y'" mutable="false" table="policy_term_history" name="com.pica.oasis.dao.CoveragePeriod">
<id name="policyTermHistoryPk" type="java.lang.Long" column="policy_term_history_pk">
<generator class="assigned"/>
</id>
<property name="effectiveFromDate" column="effective_from_date"/>
<property name="effectiveToDate" column="effective_to_date"/>
<property name="accountingFromDate" column="accounting_from_date"/>
<property name="accountingToDate" column="accounting_to_date"/>
<property name="issueStateCode" column="issue_state_code"/>
<property name="policyTermCode" column="policy_term_code"/>
<property name="polRelReasonCode" column="pol_rel_reason_code"/>
<property name="polRelStatTypeCode" column="pol_rel_stat_type_code"/>
<property name="polRelStatusCode" column="pol_rel_status_code"/>
<property name="renewalCycleCode" column="renewal_cycle_code"/>
<property name="renewalIndicatorCode" column="renewal_indicator_code"/>
<property name="recordModeCode" column="record_mode_code"/>
<many-to-one column="issue_company_entity_fk" name="issueCompany"/>
</class>
</hibernate-mapping>
Class that loads it in a collection
<hibernate-mapping>
<class where="policy_cycle_code= 'POLICY'" mutable="false" lazy="false" table="policy" name="com.pica.oasis.dao.Policy">
<id name="policyPk" type="java.lang.Long" column="policy_pk">
<generator class="assigned"/>
</id>
<property name="policyNumber" column="policy_no"/>
<many-to-one column="policy_type_code" name="policyType"/>
<property name="polCurrStatusCode" column="pol_curr_status_code"/>
<property name="policyCycleCode" column="policy_cycle_code"/>
<set inverse="true" order-by="accounting_to_date desc, effective_to_date desc" lazy="false" name="coveragePeriods">
<key column="policy_fk"/>
<one-to-many class="com.pica.oasis.dao.CoveragePeriod"/>
</set>
</class>
</hibernate-mapping>
The generated SQL (show_sql=true):
SQL generated by using session.load() to load the class by id:
Hibernate: select coveragepe0_.policy_term_history_pk as policy1_1_, coveragepe0_.effective_from_date as effective2_7_1_, coveragepe0_.effective_to_date as effective3_7_1_, coveragepe0_.accounting_from_date as accounting4_7_1_, coveragepe0_.accounting_to_date as accounting5_7_1_, coveragepe0_.issue_state_code as issue6_7_1_, coveragepe0_.policy_term_code as policy7_7_1_, coveragepe0_.pol_rel_reason_code as pol8_7_1_, coveragepe0_.pol_rel_stat_type_code as pol9_7_1_, coveragepe0_.pol_rel_status_code as pol10_7_1_, coveragepe0_.renewal_cycle_code as renewal11_7_1_, coveragepe0_.renewal_indicator_code as renewal12_7_1_, coveragepe0_.record_mode_code as record13_7_1_, coveragepe0_.issue_company_entity_fk as issue14_7_1_, entity1_.entity_pk as entity1_0_, entity1_.client_id as client2_3_0_, entity1_.date_of_birth as date3_3_0_, entity1_.email_address1 as email4_3_0_, entity1_.email_address2 as email5_3_0_, entity1_.email_address3 as email6_3_0_, entity1_.entity_type as entity7_3_0_, entity1_.federal_tax_id as federal8_3_0_, entity1_.first_name as first9_3_0_, entity1_.last_name as last10_3_0_, entity1_.middle_name as middle11_3_0_, entity1_.organization_name as organiz12_3_0_, entity1_.prefix_name as prefix13_3_0_, entity1_.social_security_number as social14_3_0_, entity1_.suffix_name as suffix15_3_0_, entity1_.default_tax_id as default16_3_0_ from policy_term_history coveragepe0_ left outer join entity entity1_ on coveragepe0_.issue_company_entity_fk=entity1_.entity_pk where coveragepe0_.policy_term_history_pk=? and coveragepe0_.base_record_b = 'Y'
SQL generated when loaded through a collection mapping:
Hibernate: select coveragepe0_.policy_fk as policy15_2_, coveragepe0_.policy_term_history_pk as policy1_2_, coveragepe0_.policy_term_history_pk as policy1_1_, coveragepe0_.effective_from_date as effective2_7_1_, coveragepe0_.effective_to_date as effective3_7_1_, coveragepe0_.accounting_from_date as accounting4_7_1_, coveragepe0_.accounting_to_date as accounting5_7_1_, coveragepe0_.issue_state_code as issue6_7_1_, coveragepe0_.policy_term_code as policy7_7_1_, coveragepe0_.pol_rel_reason_code as pol8_7_1_, coveragepe0_.pol_rel_stat_type_code as pol9_7_1_, coveragepe0_.pol_rel_status_code as pol10_7_1_, coveragepe0_.renewal_cycle_code as renewal11_7_1_, coveragepe0_.renewal_indicator_code as renewal12_7_1_, coveragepe0_.record_mode_code as record13_7_1_, coveragepe0_.issue_company_entity_fk as issue14_7_1_, entity1_.entity_pk as entity1_0_, entity1_.client_id as client2_3_0_, entity1_.date_of_birth as date3_3_0_, entity1_.email_address1 as email4_3_0_, entity1_.email_address2 as email5_3_0_, entity1_.email_address3 as email6_3_0_, entity1_.entity_type as entity7_3_0_, entity1_.federal_tax_id as federal8_3_0_, entity1_.first_name as first9_3_0_, entity1_.last_name as last10_3_0_, entity1_.middle_name as middle11_3_0_, entity1_.organization_name as organiz12_3_0_, entity1_.prefix_name as prefix13_3_0_, entity1_.social_security_number as social14_3_0_, entity1_.suffix_name as suffix15_3_0_, entity1_.default_tax_id as default16_3_0_ from policy_term_history coveragepe0_ left outer join entity entity1_ on coveragepe0_.issue_company_entity_fk=entity1_.entity_pk where coveragepe0_.policy_fk=? order by coveragepe0_.accounting_to_date desc, coveragepe0_.effective_to_date desc
|