-->
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: Discuss : To get entire table data through session
PostPosted: Thu Aug 02, 2007 4:41 am 
Newbie

Joined: Thu May 17, 2007 10:51 am
Posts: 16
Hey everybody,
I am new to hibernate.



I have a discussion that, to get entire table data through hibernate I am using the following code.......

DBSessionFactoryLocal dbSessionFactory = (DBSessionFactoryLocal) SpringUtil.getBean(DBSessionFactoryLocal.ID);
DBSession dbSession = dbSessionFactory.currentSession();
Session session = dbSession.getSession();
try {
Query query = session.getNamedQuery(Constants.GET_COUNTRY_DATA_QUERY);
List results = query.list();
if (CollectionsUtil.isEmptyCollection(results)) {
throw new NoDataFoundException("No States found");
}
return (States[]) results.toArray(new States[0]);
} finally {
if (dbSessionFactory != null) {
dbSessionFactory.closeCurrentSession();
}
}


Is there any other way to get data without firing a query.
(Something like using session.get() method...........)


Can anybody please help me on this.


Thanks in advance.

_________________
Manic


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 02, 2007 4:46 am 
Newbie

Joined: Wed Aug 01, 2007 4:53 pm
Posts: 11
the first time, you have to query offcourse, but then, you could save it in the session and when you call the function later, you just get the session var.
I'll write some pseude code for now...

Code:
if session.get("states") == null then
   session.put("states",states);
end if
return session.get("states");


this is rather easy as you can see. The implementation offcourse depends on the architecture... jsp, jfs,...


Top
 Profile  
 
 Post subject: RE:
PostPosted: Thu Aug 02, 2007 6:02 am 
Newbie

Joined: Thu May 17, 2007 10:51 am
Posts: 16
Hey,
You said about the context session thing, but here I am using a Hibernate session.



This is happening in the ejb layer.......

_________________
Manic


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.