I am getting the following error
Exception in thread “main” java.lang.ClassCastException: org.hibernate.impl.SessionFactoryImpl cannot be cast to
in.codejava.spring.withHibernate.customer.dao.impl.HibCustomer at
in.codejava.spring.withHibernate.App.main(App.java:15)
This is the line from my code:
ApplicationContext context= new ClassPathXmlApplicationContext("Spring-Module.xml");
HibCustomer CustomerDao = (HibCustomer) context.getBean("sessionFactory");
What could be the error?
In general it is very likely that object by name “sessionFactory” is not instance of HibCustomer. In your case it is obvious, just look the stack trace. It tells you that you cannot cast instance of org.hibernate.impl.SessionFactoryImpl to in.codejava.spring.withHibernate.customer.dao.impl.HibCustomer.
Most likely you want to cast it to the SessionFactory and continue from there: