Autocomplete, connection does not exist

2011-05-16
2013-01-31
  • Claudio Rossi

    Claudio Rossi - 2011-05-16

    Hi at all i'm new of this forum and i hope to find an aswer to my question.

    I implement ajaxtag in my web application.

    I used a Servlet that was ask from the jsp.

    this Servlet do an DB query using Hibernate but when i do criteria.list() for have the response to my DB the system says that "connection does not exist"

    I have no idea why the system says that.

    this is the code of my web.xml
    <servlet>
            <servlet-name>autocomplete</servlet-name>
            <servlet-class>it.cabro.ajax.AutoComplete</servlet-class>
            <load-on-startup>2</load-on-startup>
        </servlet>
    <!- Action Servlet Mapping ->
        <servlet-mapping>
            <servlet-name>action</servlet-name>
            <url-pattern>*.do</url-pattern>
        </servlet-mapping>
        <servlet-mapping>
            <servlet-name>autocomplete</servlet-name>
            <url-pattern>/autocomplete.view</url-pattern>
        </servlet-mapping>

    and there is the code of my autocomplete.java:

    String funzione = Util.filtraNull(request.getParameter("funzione"));
         
            AjaxXmlBuilder axb = new AjaxXmlBuilder();
            UserContainer userContainer = (UserContainer) request.getSession().getAttribute("userContainer");
            Session session = null;
            try
            {
              
                DataBaseAS400 dbAS400 = null;
                try
                {
                    dbAS400 = new DataBaseAS400(userContainer);
                }
                catch(Exception e)
                {
                    log.error("", e);
                }
                try
                {
    //                session = HibernateUtil.getFirstSessionAS400(userContainer);
                    session = HibernateUtil.currentSessionAS400(userContainer);
                }
                catch(Exception e)
                {
                    axb.addItem(Util.escapeSpecialChar(e.getMessage()), "");
                    return axb.toString();
                }
               
                if(funzione.equals("codiceCliente"))
                {
                    String ricerca = Util.filtraNull(request.getParameter("descrizioneFornitore").toUpperCase());
                    if(ricerca.equals(""))
                        return axb.toString();
                    try
                    {
                        Criteria criteria = session.createCriteria(Gcacm00f.class);
                        criteria = criteria.add(Restrictions.like("gcdsc1", ricerca.trim(), MatchMode.ANYWHERE));
                       
                        List<Gcacm00f> lista = (List<Gcacm00f>) criteria.list();
                        log.debug("SIZE=" + lista.size());
                        for(Gcacm00f elem : lista)
                        {
                            axb.addItem(Util.escapeSpecialChar(elem.getDescrizioneEstesa()), elem.getGcid());
                        }
                       
                    }
                    catch(Exception ex)
                    {
                        log.error("", ex);
                    }
                }
            }
            finally
            {
                try
                {
    //            if(userContainer != null && userContainer.getConn() != null && !userContainer.getConn().isClosed())
                    if(userContainer != null && !userContainer.isCloseConnection())
                    {
                        log.debug("CHIUDO SESSIONE HIBERNATE ");
                        HibernateUtil.closeSessionAS400(userContainer);
                        log.debug("CHIUDO CONNESSIONE");
                        //userContainer.getConn().close();
                    }
                }
                catch(Exception e)
                {
                    log.error(e.getMessage(), e);
                }
            }
    //        if(userContainer != null)
    //            userContainer.setConn(null);
            if(axb.isEmpty())
            {
                axb.addItem("Nessun record trovato", "§§§");
            }
            return axb.toString();
        }

    thank for the next answer. and i'm terible sorry for my bad English.

    Bye

     
  • Victor Homyakov

    Victor Homyakov - 2011-05-31

    Although this problem is not related to AjaxTags, I think you should:
    1. Separate your DB-related code from Action (DB-tier from Web-tier, read more about MVC)
    2. Write in your IDE some tests to check DB connection and receive some responses from your DB
    3. Check your connection configuration in hibernate.properties or where you have it
    4. Make your tests working with your confiruration

     

Log in to post a comment.