-->
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: opens ession problem
PostPosted: Tue Feb 20, 2007 5:10 am 
Newbie

Joined: Thu Jan 11, 2007 9:23 am
Posts: 5
hi all,
I run the code and get
java.lang.NullPointerException
roseindia.web.SearchTutorialAction.execute(SearchTutorialAction.java:41)
can any one tell me how to open session

[code]
package roseindia.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletContext;

import java.util.List;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import roseindia.net.plugin.HibernatePlugIn;

import roseindia.net.dao.hibernate.Tutorial;

import org.hibernate.SessionFactory;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Restrictions;
import org.hibernate.Criteria;



public class SearchTutorialAction extends Action
{
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
SearchTutorialActionForm formObj = (SearchTutorialActionForm)form;


ServletContext context = request.getSession().getServletContext();
/*Retrieve Session Factory */
SessionFactory _factory = (SessionFactory)
context.getAttribute(HibernatePlugIn.SESSION_FACTORY_KEY);
/*Open Hibernate Session */
Session session = _factory.openSession();
//Criteria Query Example
Criteria crit = session.createCriteria(Tutorial.class);
crit.add(Restrictions.like("shortdesc","% + formObj.getKeyword() +%")); //Like condition

//Fetch the result from database
List tutorials= crit.list();
request.setAttribute("searchresult",tutorials);

/*Close session */
session.close();
System.out.println("Hibernate Session Closed");
return mapping.findForward("success");
}
}[/code]


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.