-->
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.  [ 5 posts ] 
Author Message
 Post subject: Problem w/lightweight impl
PostPosted: Wed Mar 03, 2004 10:43 am 
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)
...

===============================


Top
  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 1:42 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Is HeavyweightSalesPacketVO a subclass of SalesPacketVO

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 2:21 pm 
Yes. Sorry about forgetting to mention that. Wanna see the code?


Top
  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 6:00 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hum is your code as simple as that ?
try to remove any extra property and association, then add it one by one

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2004 2:13 am 
I figured it out, and your comments were definitely on the right track. It turns out that some of the grand-child entities of HeavyweightSalesPacketVO were of type SalesPacketVO - its superclass. Due to this incestuous relationship in which an object's parent is also its grandchild, the following code (in Loader.java) would throw an exception since

HeavyweightSalesPacketVO.class.isAssignableFrom(SalesPacketVO.class)

is false.

...
private void instanceAlreadyLoaded(ResultSet rs, int i, Loadable persister, String suffix, Key key, Object object, LockMode lockMode, SessionImplementor session)
throws HibernateException, SQLException {

if ( !persister.getMappedClass().isAssignableFrom( object.getClass() ) )
throw new WrongClassException( "loaded object was of wrong class", key.getIdentifier(), persister.getMappedClass() );
...

Incest is bad, so HeavyweightSalesPacketVO's children's mappings to SalesPacketVO were changed to HeavyweightSalesPacketVO. It turns out that the children are only obtained through a SalesPacketVO instance so we don't have to worry about needlessly loading the heavyweight object. I don't know why the references are there in the first place.

Thank you very much for the prompt response.

Atif Faridi


Top
  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.