-->
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.  [ 3 posts ] 
Author Message
 Post subject: Use of FetchMode
PostPosted: Thu Feb 26, 2004 8:27 am 
Beginner
Beginner

Joined: Thu Feb 26, 2004 6:59 am
Posts: 47
Location: Gurgaon, India
Hello,

We are trying lazy data fetching using fetchMode. But it is not working as mentioned in

documentation. We tried this property with primitive, and also with collection but did't get

required results, means it is not fetching collection items lazily but fetching these with the

main object. Please let me know how to use this property. I am giving the mapping files and code

segment of example:



Mapping file for collection (Document.LineItem):
-------------------------------------------------

<?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.aceva.rms.knowledge.config.Document" table="Document"

proxy="com.aceva.rms.knowledge.config.Document">
<id name="id" column="document_id" type="long" unsaved-value="null">
<generator class="hilo"/>
</id>
<property name="documentAmount" column="document_amount" type="float"/>
<property name="documnetDate" column="document_date" type="date"/>

<set name="docExceptions" cascade="all" inverse="true" lazy="true">
<key column="document_id"/>
<one-to-many class="com.aceva.rms.knowledge.config.Exception_To_Document"/>
</set>
<set name="docScopes" cascade="all" inverse="true" lazy="true">
<key column="document_id"/>
<one-to-many class="com.aceva.rms.knowledge.config.Document_To_Scope"/>
</set>
<set name="lineItems" cascade="all" inverse="true" lazy="true">
<key column="document_id"/>
<one-to-many class="com.aceva.rms.knowledge.config.Line_Item"/>
</set>

<joined-subclass name="com.aceva.rms.knowledge.config.Adjustment" table="Adjustment"

proxy="com.aceva.rms.knowledge.config.Adjustment">
<key column="sid"/>
<property name="accountNumber" column="account_number" type="string"

length="30" not-null="true"/>
</joined-subclass>
</class>

</hibernate-mapping>

Code :
--------------

private void testDocument(){
Session session = null;
try{ //
session = HibernateUtils.currentSession();
Criteria criteria = session.createCriteria(Document.class)
.add( Expression.eq( "id", new Long(65537)))
.setFetchMode("lineItems", FetchMode.LAZY)


List list = criteria.list();
for (int i = 0; i < list.size(); i++)
{
Document document = (Document) list.get(i);
logMessage("document Fetched! > " + document);
Collection lineItems = document.getLineItems();
logMessage("size : " + lineItems.size());
logMessage("asked for definition!");
}
}
catch(Throwable ex){
logMessage("Exception while fetching document! msg > " + ex.getMessage());
ex.printStackTrace();
}
finally{
try{
session.flush();
session.connection().rollback();
HibernateUtils.closeSession();
}
catch(Throwable daoExp){
logMessage("Exception while closing session! msg > " + daoExp.getMessage());
daoExp.printStackTrace();
}
}
}




Thanks,

_________________
Mohit Gupta
Software Engineer
Gurgaon, India


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2004 8:49 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
asking lineItems.size() will load the collection.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 1:23 am 
Beginner
Beginner

Joined: Thu Feb 26, 2004 6:59 am
Posts: 47
Location: Gurgaon, India
You are right, that listItems.size should fetch the collection items. We achieved this by setting lazy property in mapping file. But can we achieve this using fetch mode as well?

And also whats about other associated data objects, if we want to fetch these lazily.

_________________
Mohit Gupta
Software Engineer
Gurgaon, India


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