-->
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: java.lang.ClassCastException and Struts -Please help
PostPosted: Mon Dec 20, 2004 9:47 am 
Beginner
Beginner

Joined: Sun Sep 07, 2003 9:04 am
Posts: 48
Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


I am using C:\jboss-4.0.0DR4\jboss-4.0.0DR4 and C:\j2sdk1.4.2_04.

I have relativ small code. that give me java.lang.ClassCastException, after while I decided to look for help.
Her.
*************************************************************public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws HibernateException
{
UserForm loginForm = (UserForm)form;
_RootDAO.initialize();
Session session =_RootDAO.createSession();
try {

Persons p = new Persons();
p.setFirstName("sofus");
p.setId(new Integer(2));
p.setLastName("julius");
session.save(p);
} catch (Exception e) {
e.printStackTrace();

} finally {

session.close();
}
if (loginForm.getUsererName().equals("jln")
&& loginForm.getPassword().equals("jln")) {
request.setAttribute("userName", loginForm.getUsererName());
return mapping.findForward("success");
}

return mapping.findForward("failure");

}
************************************************************
and her is hibernate.cfg.xml
************************************************************
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
<session-factory name="java:hibernate/SessionFactory">

<!-- datasource connection properties -->
<property name="connection.datasource">java:/OracleDS</property>
<!-- dialect for Oracle (any version) -->
<property name="dialect">
org.hibernate.dialect.OracleDialect
</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.use_outer_join">true</property>
<property name="hibernate.transaction.factory_class">
net.sf.hibernate.transaction.JBossTransactionManagerLookup
</property>
<property name="jta.UserTransaction">
java:comp/UserTransaction
</property>
<mapping resource="Persons.hbm.xml" />
<mapping resource="Reservations.hbm.xml" />
<mapping resource="Flights.hbm.xml" />
</session-factory>
</hibernate-configuration>
************************************************************
And her is the errors
*************************************************************
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:545)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:486)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)


root cause

java.lang.ClassCastException
net.sf.hibernate.transaction.TransactionFactoryFactory.buildTransactionFactory(TransactionFactoryFactory.java:34)
net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:77)
net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1160)
net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:794)
src.base._BaseRootDAO.initialize(_BaseRootDAO.java:54)
src.base._BaseRootDAO.initialize(_BaseRootDAO.java:38)
com.yourcompany.struts.action.LoginAction.execute(LoginAction.java:52)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)


note The full stack trace of the root cause is available in the Apache Tomcat/5.0.25 logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.0.25


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 21, 2004 11:57 am 
Newbie

Joined: Tue Dec 21, 2004 11:50 am
Posts: 3
I had exactly the same problem. The ClassCastException is caused because the hibernate TransactionFactoryFactory has loaded a class from the hibernate2.jar packaged your ear file, while the TransactionFactoryFactory is loaded from the hibernate2.jar in your jboss/lib directory.

For more info, read on the wiki on advanced class loading. To summarize : two classes are not identical unless they run in the same classloader.

So what is the solution ? Remove your hibernate2.jar either from your ear or from your jboss/lib.

I removed it from the ear. I had to make sure that the ehcache.jar also appeared in the jboss/lib.

Best regards,

Kristof


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 9:05 am 
Newbie

Joined: Tue Feb 15, 2005 7:57 am
Posts: 5
Hi Kristof,
I have a similar error but with Sun application server. Do you have any idea of how to fix it?
This is the stack trace of the error:


Class Name: net.sf.hibernate.transaction.TransactionFactoryFactory
File Name: TransactionFactoryFactory.java
Method Name: buildTransactionFactory
Line Number: 34

51: cfg.configure();
52: else
53: cfg.configure(configFileName);
54: setSessionFactory(configFileName, cfg.buildSessionFactory());
55: }
56: }
57:


Stack Trace:

net.sf.hibernate.transaction.TransactionFactoryFactory.buildTransactionFactory(TransactionFactoryFactory.java:34)
net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:77)
net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1172)
net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:803)
amanda.base._BaseRootDAO.initialize(_BaseRootDAO.java:54)
amanda.base._BaseRootDAO.initialize(_BaseRootDAO.java:38)
cacharreo.Page1.button1_action(Page1.java:131)
sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-2)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:324)
com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:126)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
javax.faces.component.UICommand.broadcast(UICommand.java:312)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-2)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:324)
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:246)
java.security.AccessController.doPrivileged(AccessController.java:-2)
javax.security.auth.Subject.doAsPrivileged(Subject.java:500)
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:268)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:236)
org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:55)
org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:145)
java.security.AccessController.doPrivileged(AccessController.java:-2)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:141)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:109)
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:522)
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:214)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:168)
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:109)
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:522)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:144)
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:109)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:133)
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:107)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:539)
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:107)
com.sun.enterprise.webservice.EjbWebServiceValve.invoke(EjbWebServiceValve.java:134)
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:107)
com.sun.enterprise.security.web.SingleSignOn.invoke(SingleSignOn.java:254)
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:107)
com.sun.enterprise.web.VirtualServerValve.invoke(VirtualServerValve.java:209)
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:107)
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:522)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:114)
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:109)
com.sun.enterprise.web.VirtualServerMappingValve.invoke(VirtualServerMappingValve.java:166)
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:107)
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:522)
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:936)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:165)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:683)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:604)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:542)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:647)
java.lang.Thread.run(Thread.java:534)

thank you!


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.