简体   繁体   中英

com.ibm.websphere.servlet.error.ServletErrorReport: java.lang.NoClassDefFoundError: org.hibernate.impl.SessionFactoryImpl


I am unable to create the session factory object. When I put the log statement line by line, code is failing at HibernateUtil.createSessionFactory() method. Can you please help where am I going wrong here ? I am attaching all the relevent code which I am using.
I think the error is misleading as it suggests the error as
1. "ClassNotFoundException: org.objectweb.asm.Type" inspite the availability of asm-1.5.3.jar.
2. com.ibm.websphere.servlet.error.ServletErrorReport: java.lang.NoClassDefFoundError: org.hibernate.impl.SessionFactoryImpl
All the hibernate 3 related jar files are in classpath Below are the code

1. tsrHibernate.cfg.xml

<?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>
        <property name="hibernate.connection.datasource">Template-DS</property> 
        <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
        <property name="show_sql">true</property>

        <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
        <property name="hibernate.hbm2ddl.auto">update</property>
        <property name="SetBigStringTryClob">true</property>
        <property name="batch_size">0</property>

        <mapping resource="com/ibm/aodt/isrvce/hibernate/mappings/CommonRequestsTemplates.hbm.xml"/>
        <mapping resource="com/ibm/aodt/isrvce/hibernate/mappings/Tsr.hbm.xml"/>
        <mapping resource="com/ibm/aodt/isrvce/hibernate/mappings/Sequence.hbm.xml" />
        <mapping resource="com/ibm/aodt/isrvce/hibernate/mappings/lovvalues.hbm.xml" /> 
        <mapping resource="com/ibm/aodt/isrvce/hibernate/mappings/Asset.hbm.xml" />
        <mapping resource="com/ibm/aodt/isrvce/hibernate/mappings/AssetEnvAssociation.hbm.xml" />
        <mapping resource="com/ibm/aodt/isrvce/hibernate/mappings/Environment.hbm.xml" />
        <mapping resource="com/ibm/aodt/isrvce/hibernate/mappings/AutomationEnvAuthentication.hbm.xml" />
        <mapping resource="com/ibm/aodt/isrvce/hibernate/mappings/AutomationContentType.hbm.xml" />
        <mapping resource="com/ibm/aodt/isrvce/hibernate/mappings/Language.hbm.xml" />
        <mapping resource="com/ibm/aodt/isrvce/hibernate/mappings/AutomationEnvContents.hbm.xml" />
        <mapping resource="com/ibm/aodt/isrvce/hibernate/mappings/Customer.hbm.xml" />
        <mapping resource="com/ibm/aodt/isrvce/hibernate/mappings/ScoreIsrvceFileUpload.hbm.xml" />
        <mapping resource="com/ibm/aodt/isrvce/hibernate/mappings/AutomationLookup.hbm.xml" />
    </session-factory>

</hibernate-configuration>

2. CommonRequestsTemplates.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping 
    package="com.ibm.aodt.isrvce.hibernate.mappings"  default-lazy="false">

    <class name="com.ibm.aodt.isrvce.hibernate.mappings.CommonRequestsTemplates" table="COMMON_REQUESTS_TEMPLATES">
            <id name="id">
            <column name="id" not-null="true"/>
            <generator class="native"/>
        </id>
        <property name="parentId" type="int">
            <column name="parent_id" length="4" not-null="false"/>
        </property>
        <property name="templateName" type="string">
            <column name="template_name" length="150" not-null="false"/>
        </property>
        <property name="templateId" type="string">
            <column name="template_id" length="10" not-null="false"/>
        </property>
        <property name="sortOrder" type="string">
            <column name="sort_order" length="10" not-null="false"/>
        </property>

        <property name="status" type="string">
            <column name="status" length="10" not-null="false"/>
        </property> 

    </class>
            <sql-query name="commonReqTempQuery">
            <return alias="commonRequestsTemplates" class="com.ibm.aodt.isrvce.hibernate.mappings.CommonRequestsTemplates"/>

            SELECT  id  AS {commonRequestsTemplates.id},
                GET_TRANSLATION_LOVVALUES(template_name,:locale) AS {commonRequestsTemplates.templateName},
                parent_id AS {commonRequestsTemplates.parentId},
                template_id AS {commonRequestsTemplates.templateId},
                sort_order AS {commonRequestsTemplates.sortOrder},
                status AS {commonRequestsTemplates.status}
                FROM common_requests_templates crt, app_org ao
                WHERE  (crt.status = 'Active' OR crt.status like '%Autom%') 
                AND crt.app_id = ao.app_id 
                AND ao.org_id = :orgId
                ORDER BY crt.sort_order

        </sql-query>


</hibernate-mapping>

3. CrtDAO.java

package com.ibm.aodt.isrvce.hibernate.dao;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.ibm.aodt.isrvce.util.HibernateUtil;
import com.ibm.aodt.isrvce.utils.TsrDaoConstants;


public class CrtDAO {

    public static String hibernateLocation = "tsrHibernate.cfg.xml";

    public static List findByOrg(String orgId, String userLocale) {
        try
        {
            Session session = HibernateUtil.currentSession( hibernateLocation);
            Transaction tx = session.beginTransaction();

            List crtList = session.getNamedQuery("commonReqTempQuery")
            .setString("orgId",orgId)
            .setString("locale",userLocale)
            .list();
            tx.commit();
            return crtList;

        } catch (HibernateException e) {
            e.printStackTrace();
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }finally{
            HibernateUtil.closeSession( hibernateLocation);
        }

    }

    private static Logger log = Logger.getLogger( CrtDAO.class );
}

4. HibernateUtil.java

package com.ibm.aodt.isrvce.util;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import java.util.HashMap;

/**
 * @author Administrator
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class HibernateUtil {

    private static HashMap sessionFactories;

    static{
        sessionFactories = new HashMap();
    }

    private static void createSessionFactory(String configFileName){
        sessionFactories.put(configFileName, new Configuration().configure(configFileName).buildSessionFactory());    // Error while invoking buildSessionFactory
    }

    private static final ThreadLocal threadLocal = new ThreadLocal();

    public static Session currentSession(String configFileName) throws HibernateException {

        SessionFactory sessionFactory = null;
        Session currentSession = null;
        HashMap sessions = null;

        synchronized(threadLocal){

            sessions = (HashMap) threadLocal.get();

            if(sessions != null){
                currentSession = (Session) sessions.get(configFileName);
            }           

            if(currentSession == null){

                sessionFactory = (SessionFactory) sessionFactories.get(configFileName);

                if(sessionFactory == null){
                    createSessionFactory(configFileName);
                    sessionFactory = (SessionFactory) sessionFactories.get(configFileName);
                }

                currentSession = sessionFactory.openSession();

                if(sessions == null){
                    sessions = new HashMap();
                }

                sessions.put(configFileName, currentSession);
                threadLocal.set(sessions);
            }
        }
        return currentSession;
    }

    public static void closeSession(String configFileName) throws HibernateException {
        HashMap sessions = null;
        synchronized(threadLocal){
            sessions = (HashMap)threadLocal.get();
            Session currentSession = (Session)sessions.get(configFileName);
            sessions.remove(configFileName);

            if(sessions.isEmpty()){
                sessions = null;
                threadLocal.set(null);
            }

            if(currentSession != null){
                currentSession.close();
            }
        }
    }
}

5. ErrorLog.txt

[1/25/17 5:54:26:605 PST] 00000040 SystemErr     R com.ibm.websphere.servlet.error.ServletErrorReport: java.lang.NoClassDefFoundError: org.hibernate.impl.SessionFactoryImpl &#40;initialization failure&#41;
[1/25/17 5:54:26:605 PST] 00000040 SystemErr     R  at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:702)
[1/25/17 5:54:26:605 PST] 00000040 SystemErr     R  at com.ibm._jsp._CommonRequestsTemplates._jspService(_CommonRequestsTemplates.java:516)
[1/25/17 5:54:26:605 PST] 00000040 SystemErr     R  at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:99)
[1/25/17 5:54:26:605 PST] 00000040 SystemErr     R  at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
[1/25/17 5:54:26:605 PST] 00000040 SystemErr     R  at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1694)
[1/25/17 5:54:26:605 PST] 00000040 SystemErr     R  at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1635)
[1/25/17 5:54:26:605 PST] 00000040 SystemErr     R  at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:149)
[1/25/17 5:54:26:605 PST] 00000040 SystemErr     R  at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
[1/25/17 5:54:26:605 PST] 00000040 SystemErr     R  at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
[1/25/17 5:54:26:605 PST] 00000040 SystemErr     R  at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:125)
[1/25/17 5:54:26:605 PST] 00000040 SystemErr     R  at com.ibm.isrvce.login.client.filter.LoginFilter.doFilter(Unknown Source)
[1/25/17 5:54:26:605 PST] 00000040 SystemErr     R  at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
[1/25/17 5:54:26:605 PST] 00000040 SystemErr     R  at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:125)
[1/25/17 5:54:26:605 PST] 00000040 SystemErr     R  at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:80)
[1/25/17 5:54:26:605 PST] 00000040 SystemErr     R  at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:908)
[1/25/17 5:54:26:605 PST] 00000040 SystemErr     R  at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:965)
[1/25/17 5:54:26:605 PST] 00000040 SystemErr     R  at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:508)
[1/25/17 5:54:26:605 PST] 00000040 SystemErr     R  at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:181)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:121)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:262)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionProcessor.handleRequest(AbstractJSPExtensionProcessor.java:353)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3994)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:276)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:945)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1592)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:191)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:454)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:516)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:307)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:278)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1662)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R Caused by: java.lang.NoClassDefFoundError: org.hibernate.impl.SessionFactoryImpl (initialization failure)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at java.lang.J9VMInternals.initialize(J9VMInternals.java:140)
[1/25/17 5:54:26:620 PST] 00000040 SystemErr     R  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1055)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at com.ibm.aodt.isrvce.util.HibernateUtil.createSessionFactory(HibernateUtil.java:31)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at com.ibm.aodt.isrvce.util.HibernateUtil.currentSession(HibernateUtil.java:55)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at com.ibm.aodt.isrvce.hibernate.dao.CrtDAO.findByOrg(Unknown Source)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at com.corio.tsr.implementations.CommonRequestsTemplatesDAO.getTemplates(Unknown Source)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at com.corio.tsr.implementations.CommonRequestsTemplatesDAO.getTopLevelParents(Unknown Source)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at com.ibm._jsp._CommonRequestsTemplates._jspService(_CommonRequestsTemplates.java:213)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  ... 38 more
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R Caused by: java.lang.NoClassDefFoundError: org.objectweb.asm.Type
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at net.sf.cglib.core.TypeUtils.parseType(TypeUtils.java:180)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at net.sf.cglib.core.KeyFactory.<clinit>(KeyFactory.java:66)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at java.lang.J9VMInternals.initializeImpl(Native Method)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at org.hibernate.impl.SessionFactoryImpl.<clinit>(SessionFactoryImpl.java:318)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at java.lang.J9VMInternals.initializeImpl(Native Method)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1055)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at com.ibm.aodt.isrvce.util.HibernateUtil.createSessionFactory(HibernateUtil.java:31)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at com.ibm.aodt.isrvce.util.HibernateUtil.currentSession(HibernateUtil.java:55)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at com.corio.tsr.implementations.ReqSearchDAO.searchReqs(Unknown Source)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at com.corio.tsr.implementations.actions.portlets.ReqSearchAction.buildNormalContext(Unknown Source)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at org.apache.jetspeed.modules.actions.portlets.JspPortletAction.buildNormalContext(JspPortletAction.java:116)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at org.apache.jetspeed.modules.actions.portlets.GenericMVCAction.doPerform(GenericMVCAction.java:169)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at org.apache.jetspeed.modules.actions.portlets.GenericMVCAction.perform(GenericMVCAction.java:126)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at org.apache.turbine.modules.ActionLoader.exec(ActionLoader.java:122)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at org.apache.jetspeed.portal.portlets.GenericMVCPortlet.buildContent(GenericMVCPortlet.java:276)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at org.apache.jetspeed.portal.portlets.GenericMVCPortlet.getContent(GenericMVCPortlet.java:207)
[1/25/17 5:54:26:636 PST] 00000040 SystemErr     R  at org.apache.jetspeed.portal.security.portlets.PortletWrapper.getContent(PortletWrapper.java:115)
[1/25/17 5:54:26:652 PST] 00000040 SystemErr     R  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[1/25/17 5:54:26:652 PST] 00000040 SystemErr     R  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
[1/25/17 5:54:26:652 PST] 00000040 SystemErr     R  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
[1/25/17 5:54:26:652 PST] 00000040 SystemErr     R  at java.lang.reflect.Method.invoke(Method.java:599)

You need the class org.hibernate.impl.SessionFactoryImpl.class in your project. Try to import hibernate-3.0.5.jar in your classpath.

The issue was not with the jar files but the folder name in which all the jars were present. May be WAS7 does not consider space as part of folder name. We renamed jar folder name used by the shared library from "SPRING HIBERNATE AND ADAMS" to "SPRING_HIBERNATE_AND_ADAMS" (space replaced with underscore) and everything started working fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM