• Post Reply Bookmark Topic Watch Topic
  • New Topic

Not able to create a hibernate session from servlets..doPost method  RSS feed

 
Praveen Ramachandran
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to call a hibernate session from doPost method of the servlet ....when i debug it,to my surprise i see that when the code for hibernate session creation is encountered the whole thing blows up resulting in an exception...

Please find the snippet below
-----------------------------

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {

response.setContentType("text/html");
String userName = request.getParameter("username");
String password = request.getParameter("password");
getServletConfig().getServletContext().setAttribute("uname", userName);
request.setAttribute("uname", userName);
request.setAttribute("password", password);

Session session = HiberUtil.getSession(); //the exception is triggered here


The exception is ......

Jul 2, 2009 2:58:45 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet CheckLogin threw exception
javax.servlet.ServletException: Servlet execution threw an exception
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:313)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)

I have tried googling it for a solution,but were in vain.Is it not possible to create a Hibernate session from doPost ()??

Can any one of you help me out? Thanks in advance!!


 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well from a design perspective you are tightly coupling your Web technology with ORM technology and your classes. A Servlets purpose is to handle an incoming request, get the info from the request, then pass it off to some other object to do your actual work. When that returns, populate the response if needed and forward to a page.

There is probably a lot more in the stack trace than you posted? Check the logs to see if there is a lot more. And also look for exceptions thrown a bit higher up in the logs than this specific exception stack trace.

Mark
 
Praveen Ramachandran
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark .As you specified in the reply i tried putting the hibernate session creation code in another class static method and tried calling the method from Servlet passing it the username and password.Again the same exception....i guess i need to introduce spring concept to it ...
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!