I have a class SalesPacketVO, whose retrieval is taking an unacceptable amount of time due to its numerous children. BTW, this is in a Struts/EJB app using Hibernate 2.0.3 against MSSQL Server 8.00.760.
After reading article #41 I have decided to move the resource-consuming children into a heavyweight class that extends SalesPacketVO, HeavyweightSalesPacketVO. In order to avoid rewriting the original client code, I have set the heavyweight object as an unmapped instance variable on the lightweight one. When an accessor of a large child is called, I check if the heavyweight object exists, if not then load it and set it, and delegate future method calls to it rather than the containing lightweight (which is now kind of a delegation layer). I am experiencing problems in the load of the heavyweight.
Thank you in advance for your kind help.
Atif Faridi
===============================
Lightweight mapping:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.terpsys.classic.data.vo.SalesPacketVO" table="SalesPacket">
<id name="id" unsaved-value="null" column="id">
<generator class="identity"/>
</id>
<property name="adverseFactorsComment"/>
<property name="alimony"/>
<property name="alternateDownPaymentComment"/>
<property name="bankruptcyComment"/>
<property name="childCare"/>
<property name="childSupport"/>
<property name="currentJudgmentsComment"/>
<property name="currentJudgmentsValue"/>
<property name="newContractAmount"/>
<property name="originalContractAmount"/>
<property name="salesPacketType" type="com.terpsys.classic.enum.SalesPacketType"/>
<property name="submissionStatus" type="com.terpsys.classic.enum.SalesPacketStatus"/>
<property name="alternateDownPayment" type="com.terpsys.classic.enum.TrueFalse"/>
<property name="adverseFactors" type="com.terpsys.classic.enum.TrueFalse"/>
<property name="readyToSubmit" type="com.terpsys.classic.enum.TrueFalse"/>
<property name="bankruptcy" type="com.terpsys.classic.enum.TrueFalse"/>
<property name="currentJudgments" type="com.terpsys.classic.enum.TrueFalse"/>
<property name="scheduleACreateDate"/>
<property name="financialInformationCreateDate"/>
<property name="projectId" insert="false" update="false"/>
<many-to-one
name="purchaser1"
class="com.terpsys.classic.data.vo.GuestVO"
column="purchaser1"
cascade="save-update"
not-null="false"/>
<many-to-one
name="purchaser2"
class="com.terpsys.classic.data.vo.GuestVO"
column="purchaser2"
cascade="save-update"
not-null="false"/>
<many-to-one
name="contract"
class="com.terpsys.classic.data.vo.ContractVO"
column="contractId"
cascade="save-update"
not-null="false"/>
<many-to-one
name="financingAddendum"
class="com.terpsys.classic.data.vo.FinancingAddendumVO"
column="financingAddendumId"
cascade="all"
not-null="false"/>
<many-to-one
name="brokerWaiver"
class="com.terpsys.classic.data.vo.BrokerWaiverVO"
column="brokerWaiverId"
cascade="all"
not-null="false"/>
<many-to-one
name="outsideLender"
class="com.terpsys.classic.data.vo.OutsideLenderVO"
column="outsideLenderId"
cascade="all"
not-null="false"/>
<many-to-one
name="outsideTitleCompany"
class="com.terpsys.classic.data.vo.OutsideTitleCompanyVO"
column="outsideTitleCompanyId"
cascade="all"
not-null="false"/>
<many-to-one
name="salesPacketSelectionSheetStatus"
class="com.terpsys.classic.data.vo.SalesPacketSelectionSheetStatusVO"
column="selectionSheetStatusId"
cascade="all"
not-null="false"/>
</class>
</hibernate-mapping>
<!-- parsed in 0ms -->
===============================
Heavyweight mapping:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.terpsys.classic.data.vo.HeavyweightSalesPacketVO" table="SalesPacket" polymorphism="explicit">
<id name="id" unsaved-value="null" column="id">
<generator class="identity"/>
</id>
<property name="adverseFactorsComment"/>
<property name="alimony"/>
<property name="alternateDownPaymentComment"/>
<property name="bankruptcyComment"/>
<property name="childCare"/>
<property name="childSupport"/>
<property name="currentJudgmentsComment"/>
<property name="currentJudgmentsValue"/>
<property name="newContractAmount"/>
<property name="originalContractAmount"/>
<property name="salesPacketType" type="com.terpsys.classic.enum.SalesPacketType"/>
<property name="submissionStatus" type="com.terpsys.classic.enum.SalesPacketStatus"/>
<property name="alternateDownPayment" type="com.terpsys.classic.enum.TrueFalse"/>
<property name="adverseFactors" type="com.terpsys.classic.enum.TrueFalse"/>
<property name="readyToSubmit" type="com.terpsys.classic.enum.TrueFalse"/>
<property name="bankruptcy" type="com.terpsys.classic.enum.TrueFalse"/>
<property name="currentJudgments" type="com.terpsys.classic.enum.TrueFalse"/>
<property name="scheduleACreateDate"/>
<property name="financialInformationCreateDate"/>
<property name="projectId" insert="false" update="false"/>
<many-to-one
name="trafficCard"
class="com.terpsys.classic.data.vo.TrafficCardVO"
column="trafficCardId"
cascade="none"
not-null="false"/>
<many-to-one
name="project"
class="com.terpsys.classic.data.vo.ProjectVO"
column="projectId"
cascade="none"
not-null="false"/>
<many-to-one
name="purchaser1"
class="com.terpsys.classic.data.vo.GuestVO"
column="purchaser1"
cascade="save-update"
not-null="false"/>
<many-to-one
name="purchaser2"
class="com.terpsys.classic.data.vo.GuestVO"
column="purchaser2"
cascade="save-update"
not-null="false"/>
<many-to-one
name="contract"
class="com.terpsys.classic.data.vo.ContractVO"
column="contractId"
cascade="save-update"
not-null="false"/>
<many-to-one
name="financingAddendum"
class="com.terpsys.classic.data.vo.FinancingAddendumVO"
column="financingAddendumId"
cascade="all"
not-null="false"/>
<many-to-one
name="brokerWaiver"
class="com.terpsys.classic.data.vo.BrokerWaiverVO"
column="brokerWaiverId"
cascade="all"
not-null="false"/>
<many-to-one
name="outsideLender"
class="com.terpsys.classic.data.vo.OutsideLenderVO"
column="outsideLenderId"
cascade="all"
not-null="false"/>
<many-to-one
name="outsideTitleCompany"
class="com.terpsys.classic.data.vo.OutsideTitleCompanyVO"
column="outsideTitleCompanyId"
cascade="all"
not-null="false"/>
<many-to-one
name="salesPacketSelectionSheetStatus"
class="com.terpsys.classic.data.vo.SalesPacketSelectionSheetStatusVO"
column="selectionSheetStatusId"
cascade="all"
not-null="false"/>
<many-to-one
name="defaultSpecialOptionRequest"
class="com.terpsys.classic.data.vo.SpecialOptionRequestVO"
column="defaultSpecialOptionRequestId"
cascade="all"
not-null="false"/>
<set name="assets" table="Asset" cascade="all-delete-orphan" inverse="true" lazy="false" order-by="assetType,description">
<key column="salesPacketId"/>
<one-to-many class="com.terpsys.classic.data.vo.AssetVO"/>
</set>
<set name="discountPromotions" table="DiscountPromotion" cascade="all-delete-orphan" inverse="true" lazy="false" order-by="description">
<key column="salesPacketId"/>
<one-to-many class="com.terpsys.classic.data.vo.DiscountPromoVO"/>
</set>
<set name="liabilities" table="Liability" cascade="all-delete-orphan" inverse="true" lazy="false" order-by="liabilityType,description">
<key column="salesPacketId"/>
<one-to-many class="com.terpsys.classic.data.vo.LiabilityVO"/>
</set>
<set name="selectedOptions" table="SelectedOption" cascade="all-delete-orphan" inverse="true" lazy="false" order-by="scheduleAOptionId">
<key column="salesPacketId"/>
<one-to-many class="com.terpsys.classic.data.vo.SelectedOptionVO"/>
</set>
</class>
</hibernate-mapping>
<!-- parsed in 0ms -->
===============================
Hibernate code:
...
try
{
Long pId = lLite.getId();
lSession = HibernateConfigurationSingleton.openSession();
lTx = lSession.beginTransaction();
lSession.evict(lLite);
//2 other things I've tried and gotten the same results:
//(1)
//lSession.evict(lSession.find("FROM com.terpsys.classic.data.vo.SalesPacketVO o WHERE o.id = ?", pId, Hibernate.LONG).get(0));
//(2)
//SessionFactory lSessionFactory = HibernateConfigurationSingleton.getSessionFactory();
//lSessionFactory.evict(SalesPacketVO.class, pId);
//This is where it bombs
lResults =
(HeavyweightSalesPacketVO) lSession.load(
HeavyweightSalesPacketVO.class,
pId);
...
===============================
Relevant part of the stack trace:
...
09:21:18,079 ERROR [SalesPacketDAO] Object with id: 778 was not of the specified subclass: com.terpsys.classic.data.vo.HeavyweightSalesPacketVO (loaded object was of wrong class)
net.sf.hibernate.WrongClassException: Object with id: 778 was not of the specified subclass: com.terpsys.classic.data.vo.HeavyweightSalesPacketVO (loaded object was of wrong class)
at net.sf.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:300)
at net.sf.hibernate.loader.Loader.getRow(Loader.java:278)
at net.sf.hibernate.loader.Loader.doFind(Loader.java:159)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:587)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:42)
at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:396)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:1889)
at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1757)
at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1688)
at com.terpsys.classic.data.dao.SalesPacketDAO.fetchHeavyweight(SalesPacketDAO.java:264)
at com.terpsys.classic.session.salespacket.SalesPacketBean.fetchHeavyweight(SalesPacketBean.java:161)
...
===============================
|