Hi,
Is the part selected in an HQL query guaranteed to be eager fetched/hydrated or do I need to use fetch join semantic to enforce this ?
party is a many-to-one relationship with lazy load enabled by default.
The following query will return fully initialized objects.
select distinct psl.party from ProductSalesLocationImpl psl
where psl.product = :product
and psl.typeCd = :typeCd
However it happened once that it returned a proxy object for PartyImpl. Should I add fetch join psl.party to my HQL query to ensure this sporadic behavior does not reoccur ?
Hibernate version:
3.2.4sp1
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" [
<!ENTITY types SYSTEM "classpath://mappings/rdo-types.xml">
<!ENTITY validityPeriod SYSTEM "classpath://mappings/validityPeriod.xml">
]>
<hibernate-mapping package="com.archinsurance.reference.entity.impl">
&types;
<class name="ProductSalesLocationImpl" table="PRODUCT_SALES_LOCATION">
<composite-id name="id" class="ProductSalesLocationPK">
<key-property name="geographicAreaId" column="GEOGRAPHIC_AREA_ID" type="int" />
<key-property name="partyId" column="PARTY_ID" type="long" />
<key-property name="productId" column="SPECIFICATION_ID" type="long" />
</composite-id>
<property name="typeCd" column="TYPE_CD" type="pslTypeCode" />
<property name="statusCd" column="STATUS_CD" />
&validityPeriod;
<set name="previousVersionMapping" inverse="true">
<key>
<column name="GEOGRAPHIC_AREA_ID" />
<column name="PARTY_ID" />
<column name="SPECIFICATION_ID" />
</key>
<one-to-many class="com.archinsurance.reference.entity.diff.impl.ProductSalesLocationDiffImpl" />
<filter name="previousVersionDiffRows" condition="WM_DIFFVER = :workspaceSavepointCombo" />
</set>
<many-to-one name="geographicalArea" class="GeographicalAreaImpl" column="GEOGRAPHIC_AREA_ID" insert="false"
update="false" cascade="refresh">
</many-to-one>
<many-to-one name="party" class="com.archinsurance.reference.entity.party.impl.PartyImpl" column="PARTY_ID"
insert="false" update="false" cascade="refresh">
</many-to-one>
<many-to-one name="product" class="ProductImpl" column="SPECIFICATION_ID" insert="false" update="false"
cascade="refresh">
</many-to-one>
<many-to-one name="referenceDomainRelationInstance" class="ReferenceDomainRelationInstanceImpl"
column="DOMAIN_OBJECT_INSTANCE_ID" cascade="refresh">
</many-to-one>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" [
<!ENTITY validityPeriod SYSTEM "classpath://mappings/validityPeriod.xml">
<!ENTITY types SYSTEM "classpath://mappings/rdo-types.xml">
]>
<!--
Mapping file for the PartyImpl Class and its subclasses.
@author Rajeev Aggarwal
-->
<hibernate-mapping>
&types;
<class name="com.archinsurance.reference.entity.party.impl.PartyImpl" table="Party">
<!-- Common id property. -->
<id name="id" type="long" column="PARTY_ID" unsaved-value="0">
<generator class="sequence">
<param name="sequence">SEQ_PARTY_ID</param>
</generator>
</id>
<many-to-one name="partyRef" class="com.archinsurance.reference.entity.party.PartyRef" column="Party_Id"
update="false" />
<many-to-one name="refDomainInstance"
class="com.archinsurance.reference.entity.impl.ReferenceDomainInstanceImpl" column="domain_object_instance_id"
update="false" />
<property name="nameTxt" update="false" column="name_txt" />
&validityPeriod;
<set name="previousVersionMapping" inverse="true">
<key column="PARTY_ID"></key>
<one-to-many class="com.archinsurance.reference.entity.diff.impl.PartyDiffImpl" />
<filter name="previousVersionDiffRows" condition="WM_DIFFVER = :workspaceSavepointCombo" />
</set>
<joined-subclass name="com.archinsurance.reference.entity.party.impl.ArchOrganizationalUnitImpl"
table="ARCH_ORGANIZATIONAL_UNIT">
<key column="PARTY_ID" foreign-key="PARTY_ID" />
<property name="orgUnitCd" column="ORG_UNIT_CD" />
<property name="typeCd" column="TYPE_CD" type="archBusUnitTypeCode" />
<set name="previousArchOrgUnitVersion" inverse="true">
<key column="PARTY_ID"></key>
<one-to-many class="com.archinsurance.reference.entity.diff.impl.ArchOrganizationalUnitDiffImpl" />
<filter name="previousVersionDiffRows" condition="WM_DIFFVER = :workspaceSavepointCombo" />
</set>
</joined-subclass>
<joined-subclass name="com.archinsurance.reference.entity.party.impl.CarrierImpl" table="CARRIER">
<key column="PARTY_ID" foreign-key="PARTY_ID" />
<property name="archCarrierId" column="ARCH_CARRIER_ID" />
<property name="affiliateInd" type="yes_no" column="AFFILIATE_IND" />
<property name="ambestCompanyNo" column="AMBEST_COMPANY_NO" />
<property name="ambestRatingCd" column="AMBEST_RATING_CD" />
<property name="naicNo" column="NAIC_NO" />
<property name="ncciNo" column="NCCI_NO" />
<property name="isoNo" column="ISO_NO" />
<property name="naiiNo" column="NAII_NO" />
<property name="affiliateTypeCd" column="AFFILIATE_TYPE_CD" />
<property name="archIssuingCompanyCd" column="ARCH_ISSUING_COMPANY_CD" />
<property name="firstPartyFacLimitAmt" column="FIRST_PARTY_FAC_LIMIT_AMT" />
<property name="thirdPartyFacLimitAmt" column="THIRD_PARTY_FAC_LIMIT_AMT" />
<set name="previousCarrierVersion" inverse="true">
<key column="PARTY_ID"></key>
<one-to-many class="com.archinsurance.reference.entity.diff.impl.CarrierDiffImpl" />
<filter name="previousVersionDiffRows" condition="WM_DIFFVER = :workspaceSavepointCombo" />
</set>
</joined-subclass>
</class>
</hibernate-mapping>
Full stack trace of any exception that occurs:
java.lang.ClassCastException: com.archinsurance.reference.entity.party.impl.PartyImpl_$$_javassist_46
when running this:
List<ArchOrganizationalUnit orgUnits = (List<ArchOrganizationalUnit>)query.getResultList();
for(ArchOrganizationalUnit orgUnit : orgUnits) {
//
}
By the way I validated that the query does only return rows from ARCH_ORGANIZATIONAL_UNIT and none from CARRIER tables, therefore the cast to ArchOrganizationalUnit should be safe to do...
Name and version of the database you are using:
Oracle 10g
The generated SQL (show_sql=true):
select distinct partyimpl1_.PARTY_ID as PARTY1_129_, partyimpl1_.Party_Id as Party1_129_, partyimpl1_.domain_object_instance_id as domain2_129_, partyimpl1_.name_txt as name3_129_,
partyimpl1_.VALID_FROM_DT as VALID4_129_, partyimpl1_.VALID_TO_DT as VALID5_129_, partyimpl1_1_.ORG_UNIT_CD as ORG2_130_, partyimpl1_1_.TYPE_CD as
TYPE3_130_, partyimpl1_2_.ARCH_CARRIER_ID as ARCH2_131_, partyimpl1_2_.AFFILIATE_IND as AFFILIATE3_131_, partyimpl1_2_.AMBEST_COMPANY_NO as
AMBEST4_131_, partyimpl1_2_.AMBEST_RATING_CD as AMBEST5_131_, partyimpl1_2_.NAIC_NO as NAIC6_131_, partyimpl1_2_.NCCI_NO as NCCI7_131_,
partyimpl1_2_.ISO_NO as ISO8_131_, partyimpl1_2_.NAII_NO as NAII9_131_, partyimpl1_2_.AFFILIATE_TYPE_CD as AFFILIATE10_131_,
partyimpl1_2_.ARCH_ISSUING_COMPANY_CD as ARCH11_131_, partyimpl1_2_.FIRST_PARTY_FAC_LIMIT_AMT as FIRST12_131_, partyimpl1_2_.THIRD_PARTY_FAC_LIMIT_AMT as
THIRD13_131_, case when partyimpl1_1_.PARTY_ID is not null then 1 when partyimpl1_2_.PARTY_ID is not null then 2 when partyimpl1_.PARTY_ID is not null then 0 end as clazz_
from PRODUCT_SALES_LOCATION productsal0_
inner join Party partyimpl1_ on productsal0_.PARTY_ID=partyimpl1_.PARTY_ID
left outer join ARCH_ORGANIZATIONAL_UNIT partyimpl1_1_ on partyimpl1_.PARTY_ID=partyimpl1_1_.PARTY_ID
left outer join CARRIER partyimpl1_2_ on partyimpl1_.PARTY_ID=partyimpl1_2_.PARTY_ID
where productsal0_.SPECIFICATION_ID='32705' and productsal0_.TYPE_CD='BUS'
|