-->
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.  [ 1 post ] 
Author Message
 Post subject: Lazy loading using Spring HibernateTemplate
PostPosted: Sat Feb 19, 2005 3:34 am 
Newbie

Joined: Tue Jan 11, 2005 8:42 am
Posts: 3
Hi All

I have a question on lazy loading using HibernateTemplate in a Struts
app - see below:

Deal is a business object that has a collection. If I use the get
method as commented below, lazy loading fails when retrieving the
collection from the Struts tag. However, using a Query as below allows
me to do lazy load.

I do not understand why the code below works - the hibernate session
should have been closed when it got to the Struts rendering stage.

public Deal findById(int dealId) {

// return (Deal) this.getHibernateTemplate().get(Deal.class,
new Integer(dealId));

Query query = null;
try {
query = this.getHibernateTemplate().createQuery(this.getSession(),
"FROM Deal AS D " +
"WHERE D.id=" + dealId
);
Deal deal = (Deal) query.uniqueResult();
return deal;
}
catch (HibernateException eHibernate) {
log.error("Error in findById: " + eHibernate.getMessage());
}
return null;
}

Thanks
F


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.