The moose likes BEA/Weblogic and the fly likes java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Products » BEA/Weblogic
Bookmark "java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration" Watch "java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration" New topic
Author

java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration

Midhun Sivasankaran
Greenhorn

Joined: Aug 06, 2009
Posts: 16
Hi everyone,

I'm trying to add some datas to the database through session bean and Hibernate. But while adding I'm getting the following error:

<Aug 20, 2009 11:16:58 AM IST> <Error> <HTTP> <BEA-101019> <[ServletContext@6753530[app:Ptrack module:PtrackWeb path:/PtrackWeb spec-version:null]] Servlet failed with IOException
java.rmi.RemoteException: EJB Exception: ; nested exception is:
java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
at weblogic.ejb.container.internal.EJBRuntimeUtils.throwRemoteException(EJBRuntimeUtils.java:103)
at weblogic.ejb.container.internal.BaseRemoteObject.handleSystemException(BaseRemoteObject.java:857)
at weblogic.ejb.container.internal.BaseRemoteObject.handleSystemException(BaseRemoteObject.java:809)
at weblogic.ejb.container.internal.BaseRemoteObject.postInvoke1(BaseRemoteObject.java:514)
at weblogic.ejb.container.internal.StatelessRemoteObject.postInvoke1(StatelessRemoteObject.java:60)
Truncated. see log file for complete stacktrace
java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
at com.ilink.ptrack.comps.functionalityEJB.dao.functionalityDAOImpl.getFunctionalityID(functionalityDAOImpl.java:389)
at com.ilink.ptrack.comps.functionalityFacade.functionalitySessionBean.currentFunctionality(functionalitySessionBean.java:56)
at com.ilink.ptrack.comps.functionalityFacade.functionalitySession_npbzmi_EOImpl.currentFunctionality(functionalitySession_npbzmi_EOImpl.java:587)
at com.ilink.ptrack.comps.functionalityFacade.functionalitySession_npbzmi_EOImpl_CBV.currentFunctionality(Unknown Source)
at ptrack.web.Functionality.FunctionalityDelegate.currentFunctionality(FunctionalityDelegate.java:75)
Truncated. see log file for complete stacktrace
java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration
at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:296)
at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:269)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:177)
Truncated. see log file for complete stacktrace
>

I kept the hibernate3.jar file in the WEB-INF/lib folder.

Please help me on this.

Thanks & Regards,
Midhun
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


I kept the hibernate3.jar file in the WEB-INF/lib folder.

That NoClassDefFoundError appears to be coming from the EJB container. If you are using Hibernate form your EJBs you will need to put hibernate in the EJB application's classpath, not a web application's classpath.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Midhun Sivasankaran
Greenhorn

Joined: Aug 06, 2009
Posts: 16
Thanks for responding.....

Sorry to say,I kept the hibernate3.jar in WEB-INF/lib folder and set the Web application libraries classpath in EJB.

Regards,
Midhun



Midhun Sivasankaran
Greenhorn

Joined: Aug 06, 2009
Posts: 16
Midhun Sivasankaran wrote:

But I have set the path in the EJB.


Regards,
Midhun



Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

I'm not sure how WebLogic's classloaders work, so I'll move this to the WebLogic forum see if anyone over there knows.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

Put the jar directly under the EAR and change your EJB and WEB manifest so that they point to this jar. Does that solve your problem ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Midhun Sivasankaran
Greenhorn

Joined: Aug 06, 2009
Posts: 16
Hi Deepak,

I have done the same, but the error persists...

Regards,
MIdhun
Midhun Sivasankaran
Greenhorn

Joined: Aug 06, 2009
Posts: 16
Do I need to look up for Hibernate JNDI in the session bean. If yes, please help me on that....

Regards,
Midhun
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

Midhun Sivasankaran wrote:Do I need to look up for Hibernate JNDI in the session bean. If yes, please help me on that....

Regards,
Midhun


No. This is a class path problem.

Placing the JAR in the EAR should have solved the problem. Try debugging the class loader hierarchy. The class loaders that come with weblogic provide good info on toString() calls. They will give you the classpath that they can see
Midhun Sivasankaran
Greenhorn

Joined: Aug 06, 2009
Posts: 16
Can you explain it more clearly please.....

Regards,
MIdhun
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

Weblogic loads classes using a class loader hierarchy. Here is a link to the WL 9.1 class loading page

http://e-docs.bea.com/wls/docs91/programming/classloading.html

You need to understand at which stages of the class loader your class is being loaded, if it is being loaded at all. If other JARs in the EAR are being loaded correctly, you can confirm the same by obtaining this hierarchy. Get the current class loader in your code and get its parent recursively. You can then print the details of each class loader, and type cast to a specific class loader (like ChangeAwareClassLoader) and execute its methods
Midhun Sivasankaran
Greenhorn

Joined: Aug 06, 2009
Posts: 16
It works....thank you

Also I'm trying with JNDI lookup in session bean. But getting an error:

NamingException is While trying to look up comp/env/hibernate/HibernateFactory in /app/ejb/PtrackEJB.jar#functionalitySession.


See my code

hibernate.cfg.xml


<hibernate-configuration>
<session-factory name="java:comp/env/hibernate/HibernateFactory">

<property name="dialect"> org.hibernate.dialect.SQLServerDialect </property>
<property name="hibernate.jdbc.use_get_generated_keys"> false </property>
<property name="hibernate.connection.url"> jdbc:weblogic:sqlserver://164.164.40.133:1433;DatabaseName=PtrackDevelop </property>
<property name=".hibernate.connection.driver_class"> weblogic.jdbc.sqlserver.SQLServerDriver </property>
<property name="hibernate.connection.username"> ptrackdeveloper </property>
<property name="hibernate.connection.password"> ptrackdeveloper </property>
<property name="show_sql"> true </property >
<property name="jndi.name">java:comp/env/hibernate/HibernateFactory</property>
<property name="jndi.class">weblogic.jndi.WLInitialContextFactory</property>
<property name="jndi.url">t3://localhost:7001</property>
<property name="hibernate.session_factory_name">java:comp/env/hibernate/HibernateFactory</property>
<property name="hibernate.query.factory_class">
org.hibernate.hql.classic.ClassicQueryTranslatorFactory
</property>
<mapping resource="/Functionality.hbm.xml"/>

</session-factory>
</hibernate-configuration>


Sessionbean.java

private Session createHibernateBean(){
Session session = null;
try{
Context context = new InitialContext();
System.out.println("Inside Create Hibernate bean..");
SessionFactory sessionfactory = (SessionFactory)context.lookup("java:comp/env/hibernate/HibernateFactory");
System.out.println("Sesision factory..."+sessionfactory.toString());
session = sessionfactory.getCurrentSession();
}catch(NamingException ne){
System.out.println("NamingException is "+ne.getMessage());
}
return session;
}


Please help me on this.

Regards,
Midhun
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

I have minimal experience with hibernate. However i can see that the JNDI name is not bound and is causing a naming exception. Check the JNDI tree in weblogic and you will be able to find out if the name is bound correctly. You can access the JNDI tree from the admin console
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration