• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.lang.ClassCastException: org.hibernate.impl.SessionFactoryImpl cannot be cast to org.hibernate.

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Struts2 and hibernate3 for web application development.I have used the following libraries for the development
antlr-2.7.2.jar
asm-3.1.jar
asm-attrs.jar
cglib-2.2.jar
commons-collections-3.1.jar
commons-logging-1.1.3.jar
dom4j-1.6.1.jar
freemarker-2.3.19.jar
hibernate-3.2.7.ga.jar
hibernate3.jar
hibernate-commons-annotations-3.2.0.final.jar
hibernate-core-3.6.3.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
javassist-3.12.0.GA.jar
mysql-connector-java-5.0.8-bin.jar
ognl-3.0.6.jar
struts2-core-2.0.14.jar
xwork-2.0.7.jar

My hibernate.cfg.xml file is
<?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.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/UserDetails</property>
<property name="hibernate.connection.user">root</property>
<property name="hibernate.connection.password">uha123</property>
<mapping resource="com/Struts2Login/entity/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>

User.hbm.xml is
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.Struts2Login.entity.Users" table="userdetails" catalog="users">
<id name="userId" type="java.lang.Long">
<column name="Id" not-null="true" length="11"></column>
<generator class="native"/>
</id>
<property name="name">
<column name="UserName" not-null="true" length="20"></column>
</property>
<property name="password">
<column name="Password" not-null="true" length="20"></column>
</property>
<property name="email">
<column name="Email" not-null="true" length="100"></column>
</property>
<property name="rDate">
<column name="Dor" not-null="false"></column>
</property>
</class>
</hibernate-mapping>

HibernateUtil java class is
package com.Struts2Login.dao;
import java.net.URL;

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

public class HibernateUtil {

private static final SessionFactory sessionFactory=buildSessionfactory();
//private static String path="/hibernate.cfg.xml";

public static SessionFactory buildSessionfactory()
{
try {
//URL url= HibernateUtil.class.getResource(path);
Configuration config=(Configuration) new Configuration().configure().buildSessionFactory();
return (SessionFactory) config;
} catch (Throwable e) {
// TODO Auto-generated catch block
System.out.println("Initial SessionFactory creation failed \t" +e);
e.printStackTrace();
throw new ExceptionInInitializerError(e);
}

}

public static SessionFactory getSessionfactory() {
return sessionFactory;
}


}

The stacktrace i obtainned is as given below

Initial SessionFactory creation failed java.lang.ClassCastException: org.hibernate.impl.SessionFactoryImpl cannot be cast to org.hibernate.Session
java.lang.ClassCastException: org.hibernate.impl.SessionFactoryImpl cannot be cast to org.hibernate.Session
at com.Struts2Login.dao.HibernateUtil.buildSessionfactory(HibernateUtil.java:18)
at com.Struts2Login.dao.HibernateUtil.<clinit>(HibernateUtil.java:10)
at com.Struts2Login.dao.User_DAO.find(User_DAO.java:17)
at com.Struts2Login.dao.LoginAction.execute(LoginAction.java:17)
Please tell me where i get wrong ,thanks
thanks in advance
 
Ranch Hand
Posts: 814
Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

umesh annegirikar wrote:Configuration config=(Configuration) new Configuration().configure().buildSessionFactory();
return (SessionFactory) config;



What you want to do in your buildSessionfactory method with above code?
 
umesh annegirikar
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually i have resolved the problem

Thanks ,
Umesh Annegirikar
 
When people don’t understand what you are doing they call you crazy. But this tiny ad just doesn't care:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic