-->
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.  [ 11 posts ] 
Author Message
 Post subject: Problems with hibernate, maybe not thread save
PostPosted: Thu Nov 24, 2005 5:12 am 
Newbie

Joined: Mon Jun 06, 2005 4:09 am
Posts: 5
Location: Dortmund / Germany
Hello out there,
we have a big problem with hibernate 3.0.5 running under struts 1.2.4, jdk 1.4.2_08 on a tomcat 5.0.28 server connecting to an oracle9i database.

We builded an internetapplication for acquiring data. Not very extraordinary at all.

When we programmed it there are no problems at all, but when we deliverd it to our customer the problems started.
If too much users access the application at the same time we get a huge amount of errors like:
Quote:
illegally attempted to associate a proxy with two open Sessions
,
Quote:
org.hibernate.exception.GenericJDBCException: could not execute query
,
Quote:
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
,
Quote:
org.hibernate.HibernateException: Not able to obtain connection
or
Quote:
org.hibernate.AssertionFailure: possible non-threadsafe access to the session

(some Stracktraces follow below).

Here is the hibernate.cfg.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>

    <!-- Einbindung der DB-Connection ueber Tomcat-JNDI-Ressource -->
    <property name="hibernate.connection.datasource">java:comp/env/jdbc/BazDb</property>
    <property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>

    <property name="hibernate.cglib.use_reflection_optimizer">true</property>
    <property name="hibernate.show_sql">true</property>

    <property name="hibernate.c3p0.min_size">5</property>
    <property name="hibernate.c3p0.max_size">20</property>
    <property name="hibernate.c3p0.timeout">300</property>
    <property name="hibernate.c3p0.max_statements">50</property>
    <property name="hibernate.c3p0.idle_test_period">3000</property>

    <mapping resource="de/bundonline/baz/zdb/model/Zds.hbm.xml" />
    <mapping resource="de/bundonline/baz/zdb/model/Token.hbm.xml" />
    <mapping resource="de/bundonline/baz/zdb/model/Tsp.hbm.xml" />
    <mapping resource="de/bundonline/baz/zdb/model/UserRole.hbm.xml" />
    <mapping resource="de/bundonline/baz/zdb/model/WebUser.hbm.xml" />
    <mapping resource="de/bundonline/baz/zdb/model/Vst.hbm.xml" />
    <mapping resource="de/bundonline/baz/zdb/model/Zdp.hbm.xml" />
    <mapping resource="de/bundonline/baz/zdb/model/SysConfig.hbm.xml" />
    <mapping resource="de/bundonline/baz/zdb/model/UserVst.hbm.xml" />
    <mapping resource="de/bundonline/baz/zdb/model/VstVst.hbm.xml" />
    <mapping resource="de/bundonline/baz/zdb/model/Import.hbm.xml" />
    <mapping resource="de/bundonline/baz/zdb/model/News.hbm.xml" />
    <mapping resource="de/bundonline/baz/zdb/model/Tooltip.hbm.xml" />
    <mapping resource="de/bundonline/baz/zdb/model/UserSession.hbm.xml" />
  </session-factory>
</hibernate-configuration>


Now follows our Version of the HibernateUtil which handles the HibernateSessions:
Code:
package de.bundonline.baz.zdb.util;
/**
* Klasse um Hibernatesessions zu ermitteln und zu schließen
*/
import org.hibernate.*;
import org.hibernate.cfg.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
import de.bundonline.baz.zdb.ZDBConstants;

import javax.servlet.http.HttpSession;
import java.sql.Connection;

public class HibernateUtil {

    private static final SessionFactory sessionFactory;
    private static final ThreadLocal session = new ThreadLocal();
    private static final ThreadLocal transaction = new ThreadLocal();

    static {
        de.bundonline.baz.zdb.util.Log log_class = new de.bundonline.baz.zdb.util.Log ();
        Logger logger = log_class.getLogger();

        logger.info(log_class.access_message(Level.INFO, "Hibernate --- SessionFactory"));

        try {
            // Create the SessionFactory
            sessionFactory = new Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            logger.error(log_class.access_message(Level.ERROR, "Initial SessionFactory creation failed."), ex);
            logger.error("Initial SessionFactory creation failed.", ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static Session currentSession(HttpSession http_session) {
        de.bundonline.baz.zdb.util.Log log_class = (de.bundonline.baz.zdb.util.Log)http_session.getServletContext().getAttribute(ZDBConstants.ZDB_LOGGER_PARAM_NAME);
        Logger logger = log_class.getLogger();

        String sid = "unknown";

        Session s = (Session) session.get();
        // Open a new Session, if this Thread has none yet
        try {
            if (s == null || !s.isOpen()) {
                s = sessionFactory.openSession();
                session.set(s);

                if(s != null) {
                    sid = Integer.toHexString(s.hashCode());
                }
                logger.debug(log_class.access_message(Level.DEBUG, "OPEN SESSION ("+sid+") ",http_session));
            }
            else
            {
                 if(s != null) {
                    sid = Integer.toHexString(s.hashCode());
                }
                logger.debug(log_class.access_message(Level.DEBUG, "!!!REUSING SESSION ("+sid+") ", http_session));
            }

            String cid = Integer.toHexString(s.connection().hashCode());

            logger.debug(log_class.access_message(Level.DEBUG, "JDBC-Connection: " + cid, http_session));

        } catch (HibernateException e) {
            logger.error(log_class.access_message(Level.ERROR, "Can't open session: " + e.getCause(), http_session));
        }

        if(s != null) {
            sid = Integer.toHexString(s.hashCode());
        }

        return s;
    }

    public static void closeSession(HttpSession http_session) {
        de.bundonline.baz.zdb.util.Log log_class = (de.bundonline.baz.zdb.util.Log)http_session.getServletContext().getAttribute(ZDBConstants.ZDB_LOGGER_PARAM_NAME);
        Logger logger = log_class.getLogger();

        String sid = "unknown";

        Session s = (Session) session.get();
        session.set(null);
        try {
            if (s != null)
            {
                if(s != null) {
                    sid = Integer.toHexString(s.hashCode());
                }
                logger.debug(log_class.access_message(Level.DEBUG, "CLOSE SESSION ("+sid+") ",http_session));
                s.close();
                transaction.set(null);
            }
            else
            {
                logger.warn(log_class.access_message(Level.DEBUG, "Session already closed!!!", http_session));
            }
        } catch (HibernateException e) {
            logger.error(log_class.access_message(Level.ERROR, "Can't close session: " + e.getCause(), http_session));
        }
    }

    public static Transaction currentTransaction(HttpSession http_session) {
        de.bundonline.baz.zdb.util.Log log_class = new de.bundonline.baz.zdb.util.Log ();
        Logger logger = log_class.getLogger();

        String tid = "unknown";
        String sid = "unknown";

        Transaction tx = (Transaction) transaction.get();

        if(tx != null) {
            tid = Integer.toHexString(tx.hashCode());
        }

        try {
            if (tx == null) {
                Session s = currentSession(http_session);
                tx = s.beginTransaction();
                transaction.set(tx);
                if(tx != null) {
                    tid = Integer.toHexString(tx.hashCode());
                }
                if(s != null) {
                    sid = Integer.toHexString(s.hashCode());
                }
                logger.debug(log_class.access_message(Level.DEBUG, "BEGIN ("+tid+") in "+sid, http_session ));
            } else {
                logger.warn(log_class.access_message(Level.WARN, "!!! REUSING TX ("+tid+")", http_session ));
            }
        } catch (HibernateException e) {
            logger.error(log_class.access_message(Level.ERROR, "Can't open transaction: " + e.getCause(), http_session ));
        }
        return tx;
    }

    public static void commitTransaction(HttpSession http_session) {
        de.bundonline.baz.zdb.util.Log log_class = new de.bundonline.baz.zdb.util.Log ();
        Logger logger = log_class.getLogger();

        String tid = "unknown";

        Transaction tx = (Transaction) transaction.get();

        if(tx != null) {
            tid = Integer.toHexString(tx.hashCode());
        }

        try {
            if (tx != null) {
                tx.commit();
                logger.debug(log_class.access_message(Level.DEBUG, "COMMIT ("+tid+")", http_session ));
            } else {
                logger.warn(log_class.access_message(Level.WARN, "Commit: Transaction not active", http_session ));
            }
        } catch (HibernateException e) {
            logger.error(log_class.access_message(Level.ERROR, "Can't commit transaction "+tid+": " + e.getCause(), http_session));
        }
    }

    public static void rollbackTransaction(HttpSession http_session) {
        de.bundonline.baz.zdb.util.Log log_class = new de.bundonline.baz.zdb.util.Log ();
        Logger logger = log_class.getLogger();

        String tid = "unknown";

        Transaction tx = (Transaction) transaction.get();

        if(tx != null) {
            tid = Integer.toHexString(tx.hashCode());
        }

        try {
            if (tx != null) {
                tx.rollback();
                logger.debug(log_class.access_message(Level.DEBUG, "ROLLBACK ("+tid+")", http_session ));
            } else {
                logger.warn(log_class.access_message(Level.WARN, "Rollback: Transaction not active", http_session ));
            }
        } catch (HibernateException e) {
            logger.error(log_class.access_message(Level.ERROR, "Can't roolback transaction "+tid+" : " + e.getCause(), http_session));
        }
    }
}


And now a sample of code from our struts action handling ... this class is the base class from where our struts action classes are derived:

Code:
package de.bundonline.baz.zdb.view;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.struts.util.PropertyMessageResources;
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
import org.apache.commons.beanutils.PropertyUtils;
import org.hibernate.Session;
import org.hibernate.Transaction;

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

import de.bundonline.baz.zdb.ZDBConstants;
import de.bundonline.baz.zdb.model.WebUser;
import de.bundonline.baz.zdb.util.*;

/**
* Created by IntelliJ IDEA.
* Date: 24.09.2005
* Time: 16:20:02
* To change this template use File | Settings | File Templates.
*/

public abstract class zdbBaseAction extends Action{

    protected Log           log_class = null;
    protected Logger        logger = null;
    protected HttpSession   http_session = null;

    protected ActionMapping action_mapping = null;
    protected ActionForm    action_form=null;
    protected HttpServletRequest action_request=null;
    protected HttpServletResponse action_response=null;

    protected String        username = null;
    protected String        role = null;
    protected WebUser       login_user = null;

    protected Session       session=null;
    protected Transaction   tx=null;

    public String getActionName() {
        return "zdbBaseAction";
    }

    public Log getLog_class() {
        return log_class;
    }

    public void setLog_class(Log log_class) {
        this.log_class = log_class;
    }

    public Logger getLogger() {
        return logger;
    }

    public void setLogger(Logger logger) {
        this.logger = logger;
    }

    public HttpSession getHttp_session() {
        return http_session;
    }

    public void setHttp_session(HttpSession http_session) {
        this.http_session = http_session;
    }

    public ActionMapping getAction_mapping() {
        return action_mapping;
    }

    public void setAction_mapping(ActionMapping action_mapping) {
        this.action_mapping = action_mapping;
    }

    public ActionForm getAction_form() {
        return action_form;
    }

    public void setAction_form(ActionForm action_form) {
        this.action_form = action_form;
    }

    public HttpServletRequest getAction_request() {
        return action_request;
    }

    public void setAction_request(HttpServletRequest action_request) {
        this.action_request = action_request;
    }

    public HttpServletResponse getAction_response() {
        return action_response;
    }

    public void setAction_response(HttpServletResponse action_response) {
        this.action_response = action_response;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public WebUser getLogin_user() {
        return login_user;
    }

    public void setLogin_user(WebUser login_user) {
        this.login_user = login_user;
    }

    public Session getSession() {
        return session;
    }

    public void setSession(Session session) {
        this.session = session;
    }

    public Transaction getTx() {
        return tx;
    }

    public void setTx(Transaction tx) {
        this.tx = tx;
    }

    public boolean matchAction( String action_button, String match_prop ) {
        java.util.Locale myLocale;
        PropertyMessageResources myMessages;
        String actionbutton_prop = null;
        String match_string = "";

        logger.debug(log_class.access_message(Level.DEBUG, "matchAction : " + action_button + " : " + match_prop));

        try {
            myLocale = (java.util.Locale)http_session.getAttribute("org.apache.struts.action.LOCALE");
            myMessages = (PropertyMessageResources)this.getAction_request().getAttribute("org.apache.struts.action.MESSAGE");
            match_string = myMessages.getMessage(myLocale, match_prop);
            actionbutton_prop = (String) PropertyUtils.getSimpleProperty(this.getAction_form(), action_button);

            logger.debug(log_class.access_message(Level.DEBUG, "button: " + actionbutton_prop + " == " + match_string));
        } catch( Exception ex) {
            ex.printStackTrace();
        }

        return actionbutton_prop != null && actionbutton_prop.equalsIgnoreCase(match_string);
    }

    public boolean loginNeeded() {
        return true;
    }

    public boolean checkShutdownNeeded() {
        return true;
    }

    public boolean hibernateNeeded() {
        return true;
    }

    public boolean adminNeeded() {
        return false;
    }

    public boolean killResultset() {
        return true;
    }

    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response) throws Exception
    {
        this.setAction_mapping(mapping);
        this.setAction_form(form);
        this.setAction_request(request);
        this.setAction_response(response);

        log_class = (Log)request.getSession().getServletContext().getAttribute(ZDBConstants.ZDB_LOGGER_PARAM_NAME);
        logger = log_class.getLogger();

        http_session = request.getSession();
        if ( killResultset()) {
            http_session.setAttribute( "resultset", null);
        }

        logger.info(log_class.access_message(Level.INFO, "\\/==================" + getActionName() +" starts", http_session));

        if( loginNeeded() ) {
            if ( http_session.getAttribute(ZDBConstants.ZDB_LOGIN_USER_ID) == null) {
                logger.error(log_class.access_message(Level.ERROR, getActionName() + ": Unauthorized login attempt! (Session dropped!)", http_session));
                logger.info(log_class.access_message(Level.INFO, "/\\==================" + getActionName() +" ends", http_session));
                return mapping.findForward("linkfailure");
            }
        }

        role = (String)http_session.getAttribute( ZDBConstants.ZDB_LOGIN_ROLE);     // Rolle des eingeloggten Benutzers wird ermittelt
        //login_user = (WebUser)http_session.getAttribute( ZDBConstants.ZDB_LOGIN_USER);  // Eingeloggter Benuter wird ermittelt
        String userName = null;
        if (http_session.getAttribute( ZDBConstants.ZDB_LOGIN_USER_NAME) != null) {
            userName = (String)http_session.getAttribute( ZDBConstants.ZDB_LOGIN_USER_NAME);
        }
        logger.info(log_class.access_message(Level.INFO, "User: " + userName + " [" + role + "]", http_session));

        if( adminNeeded() ) {
            logger.debug(log_class.access_message(Level.DEBUG, "adminNeeded == true", http_session));
            if ( role == null || !role.equalsIgnoreCase(ZDBConstants.ZDB_ADMIN)) { // Wenn Rolle != Admin => Fehlerseite
                logger.warn(log_class.access_message(Level.WARN, getActionName() + ": A non Admin trys to acces site", http_session));
                logger.info(log_class.access_message(Level.INFO, "/\\==================" + getActionName() +" ends", http_session));
                return mapping.findForward("linkfailure");    // Refferenz auf Fehlerseite wird zurückgegeben
            }
        }

        if( hibernateNeeded() )
        {
            logger.debug(log_class.access_message(Level.DEBUG, "hibernateNeeded == true", http_session));
            try {
                session = HibernateUtil.currentSession(http_session);     // Hibernatesession wird ermittelt
                tx = HibernateUtil.currentTransaction(http_session);   // Transaktion wird gestartet
            } catch ( Exception ex ) {
                ex.printStackTrace();
                logger.error(log_class.access_message(Level.ERROR, getActionName() + ": Hibernate connection malfunction!", request.getSession()), ex.getCause());
                new de.bundonline.baz.zdb.util.Error(getActionName() + ": Hibernate connection malfunction!\n"+ex.toString(), request.getSession());

                try {
                    HibernateUtil.closeSession(http_session);
                } catch (Exception e) {
                    e.printStackTrace();
                    logger.error(log_class.access_message(Level.ERROR, "closeSession failed: " + e.getCause(), http_session));
                }

                logger.info(log_class.access_message(Level.INFO, "/\\==================" + getActionName() +" ends", http_session));
                return mapping.findForward("error");           // Fehler aufgetreten und an Fehlerseite weitergeleitet
            }

            if ( checkShutdownNeeded() && CheckShutdown.CheckState(http_session, session)) {
                logger.debug(log_class.access_message(Level.DEBUG, "checkShutdownNeeded() == true", http_session));
                HibernateUtil.commitTransaction(http_session);
                HibernateUtil.closeSession(http_session);
                logger.warn(log_class.access_message(Level.WARN, getActionName() + ": System has been shutdown", request.getSession()));

                logger.info(log_class.access_message(Level.INFO, "/\\==================" + getActionName() +" ends", http_session));
                return mapping.findForward("shutdown");               // Fehlerseitenreferenz wird zurückgegeben
            }
        }

        ActionForward forward = null;

        try {
            forward = executeAction(mapping, form, request, response );
            logger.debug(log_class.access_message(Level.DEBUG, "forward to: " + forward.toString(), http_session ));
        } catch (Exception e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            logger.error(log_class.access_message(Level.ERROR, "executeAction failed: " + e.getCause(), http_session ));
        }

        if( hibernateNeeded() )
        {
            try {
                HibernateUtil.commitTransaction(http_session);
            } catch (Exception e) {
                e.printStackTrace();
                logger.error(log_class.access_message(Level.ERROR, "commitTransaction failed: " + e.getCause(), http_session));
            } finally {
                try {
                    HibernateUtil.closeSession(http_session);
                } catch (Exception e) {
                    e.printStackTrace();
                    logger.error(log_class.access_message(Level.ERROR, "closeSession failed: " + e.getCause(), http_session));
                }
            }
        }

        logger.info(log_class.access_message(Level.INFO, "/\\==================" + getActionName() +" ends", http_session));

        return forward;
    }

    public abstract ActionForward executeAction(ActionMapping mapping,
                                                ActionForm form,
                                                HttpServletRequest request,
                                                HttpServletResponse response) throws Exception;
}


And last but not least some stacktraces:
Quote:
2005-11-23 12:07:05,201 DEBUG de.bundonline.baz.zdb [http-8001-Processor44] (HibernateUtil.java:337) 3F1E9232DD58DF19BE4CF31EF731A218 - COMMIT (e72502)
2005-11-23 12:07:05,225 DEBUG de.bundonline.baz.zdb [http-8001-Processor22] (HibernateUtil.java:337) 3F1E9232DD58DF19BE4CF31EF731A218 - COMMIT (19be7ed)
2005-11-23 12:07:05,227 DEBUG de.bundonline.baz.zdb [http-8001-Processor22] (saveZdsdataAction.java:154) saveZdsdataAction - start build ZDP Liste
2005-11-23 12:07:05,238 DEBUG de.bundonline.baz.zdb [http-8001-Processor22] (saveZdsdataAction.java:275) saveZdsdataAction - end build ZDP Liste
2005-11-23 12:07:05,241 DEBUG de.bundonline.baz.zdb [http-8001-Processor22] (HibernateUtil.java:337) 3F1E9232DD58DF19BE4CF31EF731A218 - COMMIT (19be7ed)
2005-11-23 12:07:05,242 DEBUG de.bundonline.baz.zdb [http-8001-Processor22] (zdbBaseAction.java:272) 3F1E9232DD58DF19BE4CF31EF731A218 - forward to: ForwardConfig[name=success,path=/pages/zdsdata/zdsdata.jsp,redirect=false,contextRelative=false,module=null]
2005-11-23 12:07:05,244 DEBUG de.bundonline.baz.zdb [http-8001-Processor22] (HibernateUtil.java:337) 3F1E9232DD58DF19BE4CF31EF731A218 - COMMIT (19be7ed)
2005-11-23 12:07:05,245 DEBUG de.bundonline.baz.zdb [http-8001-Processor22] (HibernateUtil.java:176) 3F1E9232DD58DF19BE4CF31EF731A218 - CLOSE SESSION (16fb1b9)

It seems that this close session shoots my cursors ...
Quote:
2005-11-23 12:07:05,247 INFO de.bundonline.baz.zdb [http-8001-Processor22] (zdbBaseAction.java:295) 3F1E9232DD58DF19BE4CF31EF731A218 - /\==================saveZdsdataAction ends
2005-11-23 12:07:05,252 DEBUG de.bundonline.baz.zdb [http-8001-Processor22] (BaseHrefUtil.java:45) 3F1E9232DD58DF19BE4CF31EF731A218 - smart:localhost localName:cmbund30 localAddr:10.6.77.124 localPort:8001
2005-11-23 12:07:05,259 DEBUG de.bundonline.baz.zdb [http-8001-Processor22] (MenuTag.java:391) 3F1E9232DD58DF19BE4CF31EF731A218 - MenuTag - Started
2005-11-23 12:07:05,261 ERROR org.hibernate.LazyInitializationException [http-8001-Processor44] (LazyInitializationException.java:19) could not initialize proxy - the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
at de.bundonline.baz.zdb.model.Zds$$EnhancerByCGLIB$$73b649e9.getVst(<generated>)
at de.bundonline.baz.zdb.view.saveZdsdataAction.buildZdpNotShowReason(saveZdsdataAction.java:63)
at de.bundonline.baz.zdb.view.saveZdsdataAction.executeAction(saveZdsdataAction.java:617)
at de.bundonline.baz.zdb.view.zdbBaseAction.execute(zdbBaseAction.java:271)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
2005-11-23 12:07:05,266 ERROR de.bundonline.baz.zdb [http-8001-Processor44] (saveZdsdataAction.java:630) CC3FE0476A26AB2251FEDF766E4DACCB - saveZdsdataAction - mainfunction mailfunction!
2005-11-23 12:07:05,267 INFO de.bundonline.baz.zdb [http-8001-Processor44] (Error.java:25) CC3FE0476A26AB2251FEDF766E4DACCB - Erroremail was generated; Text:Fehler in Klasse 'saveZdsdataAction - mainfunction mailfunction'
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
2005-11-23 12:07:05,267 DEBUG de.bundonline.baz.zdb [http-8001-Processor22] (MenuTag.java:489) 3F1E9232DD58DF19BE4CF31EF731A218 - MenuTag - Ends


and another stacktrace:
Quote:
2005-11-23 12:52:10,043 DEBUG de.bundonline.baz.zdb [http-8001-Processor22] (HibernateUtil.java:101) 68523688BFB7654DE07CEE4AFBEE933E - OPEN SESSION (c5b6c6)
2005-11-23 12:52:10,038 INFO de.bundonline.baz.zdb [http-8001-Processor6] (zdbBaseAction.java:208) 68523688BFB7654DE07CEE4AFBEE933E - \/==================editZdsdataAction starts
2005-11-23 12:52:10,048 INFO de.bundonline.baz.zdb [http-8001-Processor6] (zdbBaseAction.java:224) 68523688BFB7654DE07CEE4AFBEE933E - User: skutter [2]
2005-11-23 12:52:10,049 DEBUG de.bundonline.baz.zdb [http-8001-Processor6] (zdbBaseAction.java:237) 68523688BFB7654DE07CEE4AFBEE933E - hibernateNeeded == true
2005-11-23 12:52:10,048 DEBUG de.bundonline.baz.zdb [http-8001-Processor22] (HibernateUtil.java:113) 68523688BFB7654DE07CEE4AFBEE933E - JDBC-Connection: 1c2dea7
2005-11-23 12:52:10,052 DEBUG de.bundonline.baz.zdb [http-8001-Processor22] (HibernateUtil.java:108) 68523688BFB7654DE07CEE4AFBEE933E - !!!REUSING SESSION (c5b6c6)
2005-11-23 12:52:10,053 DEBUG de.bundonline.baz.zdb [http-8001-Processor22] (HibernateUtil.java:113) 68523688BFB7654DE07CEE4AFBEE933E - JDBC-Connection: 1c2dea7
2005-11-23 12:52:10,050 DEBUG de.bundonline.baz.zdb [http-8001-Processor6] (HibernateUtil.java:101) 68523688BFB7654DE07CEE4AFBEE933E - OPEN SESSION (863cdb)
2005-11-23 12:52:10,055 DEBUG de.bundonline.baz.zdb [http-8001-Processor22] (HibernateUtil.java:308) 68523688BFB7654DE07CEE4AFBEE933E - BEGIN (105751d) in c5b6c6
2005-11-23 12:52:10,058 DEBUG de.bundonline.baz.zdb [http-8001-Processor22] (editZdsdataAction.java:105) 68523688BFB7654DE07CEE4AFBEE933E - editZdsdataAction - action = edit
2005-11-23 12:52:10,066 DEBUG de.bundonline.baz.zdb [http-8001-Processor6] (HibernateUtil.java:113) 68523688BFB7654DE07CEE4AFBEE933E - JDBC-Connection: 1402ceb
2005-11-23 12:52:10,068 DEBUG de.bundonline.baz.zdb [http-8001-Processor6] (HibernateUtil.java:108) 68523688BFB7654DE07CEE4AFBEE933E - !!!REUSING SESSION (863cdb)
2005-11-23 12:52:10,070 DEBUG de.bundonline.baz.zdb [http-8001-Processor6] (HibernateUtil.java:113) 68523688BFB7654DE07CEE4AFBEE933E - JDBC-Connection: 1402ceb
2005-11-23 12:52:10,073 DEBUG de.bundonline.baz.zdb [http-8001-Processor22] (editZdsdataAction.java:137) 68523688BFB7654DE07CEE4AFBEE933E - editZdsdataAction - zdsdata are written to form for zds_id:4517
2005-11-23 12:52:10,076 DEBUG de.bundonline.baz.zdb [http-8001-Processor6] (HibernateUtil.java:308) 68523688BFB7654DE07CEE4AFBEE933E - BEGIN (2ab64d) in 863cdb
2005-11-23 12:52:10,080 DEBUG de.bundonline.baz.zdb [http-8001-Processor22] (editZdsdataAction.java:183) 68523688BFB7654DE07CEE4AFBEE933E - editZdsdataAction - tsp-list has benn build
2005-11-23 12:52:10,085 DEBUG de.bundonline.baz.zdb [http-8001-Processor6] (editZdsdataAction.java:105) 68523688BFB7654DE07CEE4AFBEE933E - editZdsdataAction - action = edit
2005-11-23 12:52:10,116 WARN org.hibernate.util.JDBCExceptionReporter [http-8001-Processor22] (JDBCExceptionReporter.java:71) SQL Error: 17027, SQLState: null
2005-11-23 12:52:10,118 ERROR org.hibernate.util.JDBCExceptionReporter [http-8001-Processor22] (JDBCExceptionReporter.java:72) Stream has already been closed
2005-11-23 12:52:10,122 ERROR de.bundonline.baz.zdb [http-8001-Processor22] (editZdsdataAction.java:328) 68523688BFB7654DE07CEE4AFBEE933E - editZdsdataAction - Mainfunkction mailfunction!
java.sql.SQLException: Stream has already been closed
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
at oracle.jdbc.ttc7.LongTTCItem.getChars(LongTTCItem.java:189)
at oracle.jdbc.dbaccess.DBDataSetImpl.getCharsStreamItem(DBDataSetImpl.java:1629)
at oracle.jdbc.driver.OracleStatement.getCharsInternal(OracleStatement.java:3547)
at oracle.jdbc.driver.OracleStatement.getStringValue(OracleStatement.java:3757)
at oracle.jdbc.driver.OracleResultSetImpl.getString(OracleResultSetImpl.java:460)
at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:1482)
at org.apache.commons.dbcp.DelegatingResultSet.getString(DelegatingResultSet.java:224)
at org.hibernate.type.StringType.get(StringType.java:16)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:80)
at org.hibernate.persister.entity.BasicEntityPersister.hydrate(BasicEntityPersister.java:1690)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:991)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:942)
at org.hibernate.loader.Loader.getRow(Loader.java:855)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:305)
at org.hibernate.loader.Loader.doQuery(Loader.java:412)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at de.bundonline.baz.zdb.view.editZdsdataAction.executeAction(editZdsdataAction.java:188)
at de.bundonline.baz.zdb.view.zdbBaseAction.execute(zdbBaseAction.java:271)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)


Interresting is that different users or threads have the same SessionID on this system (output in logfile over log4j ... )

It seems that a action in one thread causes problems in a complete different thread ...

Maybe someone can see our problem and can help us ... I know this is a bunch of information ....

Thank you!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 24, 2005 2:50 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Well, that's a lot of code. But I got the impression, that your binding your HB sessions to threads instead of HttpSessions. If I'm right it's just random which HttpRequest gets which HB session.

Guess the Open Session in View pattern is for you. There's a nice description in the wiki about this. http://www.hibernate.org/43.html

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 24, 2005 3:42 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Probably you store (directly or indirectly) proxies in http session.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 24, 2005 5:11 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
check this code:

de.bundonline.baz.zdb.view.saveZdsdataAction.buildZdpNotShowReason(saveZdsdataAction.java:63)
at de.bundonline.baz.zdb.view.saveZdsdataAction.executeAction(saveZdsdataAction.java:617)
at de.bundonline.baz.zdb.view.zdbBaseAction.execute(zdbBaseAction.java:271


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 25, 2005 6:31 am 
Newbie

Joined: Mon Jun 06, 2005 4:09 am
Posts: 5
Location: Dortmund / Germany
ernst_pluess wrote:
Well, that's a lot of code. But I got the impression, that your binding your HB sessions to threads instead of HttpSessions. If I'm right it's just random which HttpRequest gets which HB session.

Guess the Open Session in View pattern is for you. There's a nice description in the wiki about this. http://www.hibernate.org/43.html

HTH
Ernst


Thanks for this hint ... but we don't use hibernate 3.1.x, we are using hibernate 3.0.5. Is there an example for our version?

Björn.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 25, 2005 7:10 am 
Newbie

Joined: Mon Jun 06, 2005 4:09 am
Posts: 5
Location: Dortmund / Germany
baliukas wrote:
check this code:

de.bundonline.baz.zdb.view.saveZdsdataAction.buildZdpNotShowReason(saveZdsdataAction.java:63)
at de.bundonline.baz.zdb.view.saveZdsdataAction.executeAction(saveZdsdataAction.java:617)
at de.bundonline.baz.zdb.view.zdbBaseAction.execute(zdbBaseAction.java:271


Hi,
I checked the lines and see noting special ...
here ist the code
Code:
public void buildZdpNotShowReason ( String zdp_id, HttpSession http_session, Session session ){
        if ( zdp_id == null || zdp_id.length() == 0) {
            return;
        }
        DateFormat dateformatter;
        Date now = new Date();
        Calendar cal = Calendar.getInstance();
        cal.setTime(now);
        cal.set(Calendar.HOUR, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        now = cal.getTime();
        dateformatter = new SimpleDateFormat("dd.MM.yyyy");
        Zdp reason_zdp = (Zdp)session.load(Zdp.class, new Integer(zdp_id));
        String zdpReserveFrom = ( reason_zdp.getZdpReserveFrom() == null ? "" : dateformatter.format(reason_zdp.getZdpReserveFrom()).toString());
        String zdpReserveUntil = ( reason_zdp.getZdpReserveUntil() == null ? "" : dateformatter.format(reason_zdp.getZdpReserveUntil()).toString());
        String zdpPublication = ( reason_zdp.getZdpPublication() == null ? "" : dateformatter.format(reason_zdp.getZdpPublication()).toString());
        String zdpDepublication = ( reason_zdp.getZdpDepublication() == null ? "" : dateformatter.format(reason_zdp.getZdpDepublication()).toString());
        boolean bVstInactive=false;
        boolean bZdsInactive=false;
        boolean bZdpInactive=false;
        boolean bReserveUntilReached=false;
        boolean bPublicationNotValid=false;
        boolean bDepublicationNotValid=false;
        boolean bDontShowZdp=false;
        bVstInactive = (reason_zdp.getZds().getVst().getVstInactive() == null?false:(reason_zdp.getZds().getVst().getVstInactive().toString().equalsIgnoreCase("N")?false:true));

This above is line 63 ... nothing special ... a few lines above reason_zdp is loaded by session ... no session.close() between ....
Code:
        bZdsInactive = (reason_zdp.getZds().getZdsInactive() == null?false:(reason_zdp.getZds().getZdsInactive().toString().equalsIgnoreCase("N")?false:true));
        bZdpInactive = (reason_zdp.getZdpInactive() == null?false:(reason_zdp.getZdpInactive().toString().equalsIgnoreCase("N")?false:true));


Quote:
Probably you store (directly or indirectly) proxies in http session.

We use classes to store the hibernate result-values to prevent direct access to hibernate from within jsp-sites ... but we don't use evict() to detach the pojos ... maybe there is a problem?!

Thanks,

Björn.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 25, 2005 7:47 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
if "reason_zdp" is local variable loaded from hibernate session (it looks like this code is correct) then there are two possible problems:

1) Hibernate session was opened in different thread than "load" was called (bug with thread local stuff). Make sure hibernate session is not stored in http session or context attribute (register listeners to verify it) and search for all hibernates session type fields (it is wrong to store hibernate session in struts action or in servlet field), IDE must help to find all references in code.
2) Bug in global cache implementation (try to dissable it).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 25, 2005 8:30 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
This is wrong:

Quote:
public abstract class zdbBaseAction extends Action{

protected Log log_class = null;
protected Logger logger = null;
protected HttpSession http_session = null;

protected ActionMapping action_mapping = null;
protected ActionForm action_form=null;
protected HttpServletRequest action_request=null;
protected HttpServletResponse action_response=null;

protected String username = null;
protected String role = null;
protected WebUser login_user = null;

protected Session session=null;
protected Transaction tx=null;


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 25, 2005 10:07 am 
Newbie

Joined: Mon Jun 06, 2005 4:09 am
Posts: 5
Location: Dortmund / Germany
baliukas wrote:
This is wrong:

Quote:
public abstract class zdbBaseAction extends Action{


protected Session session=null;
protected Transaction tx=null;


Heureka ... thanks ... that was the fault .....
I changed our code and ran a test with OpenSTA with 40 nearly paralell users ... and now ... no errors ....
Greets from Dortmund ...

Björn.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 25, 2005 11:14 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
BTW remove this kind of logging:
Code:
logger.debug(log_class.access_message(Level.DEBUG, "!!!REUSING SESSION ("+sid+") ", http_session));

String concatination in many places for every "getCurrentSession" call can kill your server too.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 8:48 am 
Newbie

Joined: Mon Jun 06, 2005 4:09 am
Posts: 5
Location: Dortmund / Germany
baliukas wrote:
BTW remove this kind of logging:
Code:
logger.debug(log_class.access_message(Level.DEBUG, "!!!REUSING SESSION ("+sid+") ", http_session));

String concatination in many places for every "getCurrentSession" call can kill your server too.


Thanks, I will follow your advice.

Greets

Björn Schlaack.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 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.