-->
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: Stack Overflow in Struts Application
PostPosted: Tue Jun 28, 2005 11:10 pm 
Newbie

Joined: Tue Jun 28, 2005 10:58 pm
Posts: 2
Hi I am trying to retrieve data from MySQL table using
session.createQuery(). All I am doing is a simple user authentication.

Here is my method
Code:
private static final String QUERY_USER_BY_USER_PASSWD =
      "from Users as users" +
      " where " +
      " users.logonUser = :logonUser AND" +
      " users.logonPassword = :logonPwd";

public boolean isValidUser( String logonUser
                           ,String logonPwd)
   {
      Session session = null;
      
      try
      {
         LOG.debug("isValidUser->");
         session = DBStoreCreator.currentSession();
         Query q = session.createQuery(QUERY_USER_BY_USER_PASSWD);
         q.setParameter("logonUser", logonUser);
         q.setParameter("logonPwd", logonPwd);
         LOG.debug("query completed->");
         return  (q.list().size() == 0) ? false : true;
      }
      catch (HibernateException he)
      {
         LOG.debug("validateUser Error", he);
         return false;
      }
      finally
      {
         if ( session != null)
         {
            try
            {
               DBStoreCreator.closeSession();
            }
            catch (HibernateException heclose)
            {
               LOG.debug("isValidUser session close", heclose);
            }
         }
         
      }
   }

My hibernate helper class which is using the ThreadLocal pattern is given below too. (I just copied this from hibernate website I think).

Code:
package com.cexp.icuissues.db.utils;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;


public class DBStoreCreator {
   private static final Log LOG = LogFactory.getLog(DBStoreCreator.class);
   public static SessionFactory sessionFactory = null;

   public static final ThreadLocal session = new ThreadLocal();
   static {
      try {
         sessionFactory = new Configuration().configure()
               .buildSessionFactory();
      } catch (Throwable ex) {
         System.err.println("Initial sessionFactory creation failed" + ex);
      }
   }

   public static Session currentSession() throws HibernateException {
      Session s = (Session) session.get();
      // Open a new Session, if this thread has none yet
      if (s == null) {
         LOG.debug("->creating a new session");
         s = sessionFactory.openSession();
         // Store it in the ThreadLocal variable
         session.set(s);
      }
      return s;
   }

   public static void closeSession() throws HibernateException {
      Session s = (Session) session.get();
      if (s != null)
         s.close();
      session.set(null);
   }
}


I am calling this method isValidUser from my struts action class.

When I give an username/password which exists in the table, query fetches the record and everything works fine.

But when I enter a username/password combination which does not exists in the table, isValidUser method is called many times and I am getting a stack overflow error.

I have tested this method using JUNIT. Both the success and failure scernarios work fine there.

I am getting this problem only when I am deploying it in a container (TOMCAT)

Please help me

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 29, 2005 12:46 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
probably you made mistake in struts action (login page forward to itself if user is unauthenticated)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 29, 2005 4:47 pm 
Newbie

Joined: Tue Jun 28, 2005 10:58 pm
Posts: 2
yes that is what I did, and I figured that out this morning.
sorry about that question..

thanks a lot


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.