File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Application Frameworks and the fly likes Error creating bean with name 'sessionFactory' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Error creating bean with name Watch "Error creating bean with name New topic

Error creating bean with name 'sessionFactory'

Ivan Polak

Joined: Jan 04, 2008
Posts: 2

i have big problem with Spring 2.5, Spring MVC, Hibernate, Hibernate Annotations 3.3.0.GA and tomcat 6.0.14, acegi 1.0.6 (and ehcache 1.3.0)

in applicationContext-resources.xml :

<?xml version="1.0" encoding="UTF-8"?>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc ostgresql://localhost:5432/xxx" />
<property name="username" value="xxx" />
<property name="password" value="iwtbxfm" />
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotati on.AnnotationSessionFactoryBean">
<property name="hibernateProperties">
<prop key="hibernate.dialect">org.hibernate.dialect.Post greSQLDialect</prop>
<prop key="hibernate.query.substitutions">true 'T', false 'F'</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hibernate.generate_statistics">true </prop>

<prop key="hibernate.cache.use_second_level_cache">false </prop>

<prop key="hibernate.cache.provider_configuration_file_r esource_path">classpath:/ehcache.xml</prop>
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:/hibernate.cfg.xml"/>


<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
<mapping class=""/>

BUT after build of project a have this error:

INFO: Initializing Spring root WebApplicationContext
9.1.2008 18:43:15 org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListe ner
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext-resources.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Unable to load class declared as <mapping class=""/> in the configuration:
at AutowireCapableBeanFactory.initializeBean(Abstract
at AutowireCapableBeanFactory.doCreateBean(AbstractAu
at AutowireCapableBeanFactory$
at Method)
at AutowireCapableBeanFactory.createBean(AbstractAuto
at BeanFactory$1.getObject( 51)
at ingletonBeanRegistry.getSingleton(DefaultSingleton
at BeanFactory.getBean(
at BeanFactory.getBean(
at istableBeanFactory.preInstantiateSingletons(Defaul
at ationContext.finishBeanFactoryInitialization(Abstr



import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.CascadeType;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;

@Entity @Table(name="carrier")

public class Carrier extends BaseObject {

@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="seq_carrier")
private Long id;

private String name = null;

private String address = null;

public Carrier() {}

public Long getId() {
return id;

public void setId(Long id) { = id;

public String getName() {
return name;

public void setName(String name) { = name;

public String getAddress() {
return address;

public void setAddress(String address){
this.address = address;

public boolean equals(Object o) {
if (this == o) {
return true;
if (!(o instanceof Carrier)) {
return false;

final Carrier carrier = (Carrier) o;

return !(name != null ? !name.equals(carrier.getName()) : carrier.getName() != null);


public int hashCode() {
return (name != null ? name.hashCode() : 0);

public String toString() {
return null;

in web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="" xmlns:xsi="" xsi:schemaLocation="">


<!-- Context Configuration locations for Spring XML files -->

<servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>


<filter-name>Acegi Filter Chain Proxy</filter-name>

<filter-name>Acegi Filter Chain Proxy</filter-name>

org.springframework.web.context.ContextLoaderListe ner



please, where is the problem ?


ajse ruku
Ranch Hand

Joined: May 06, 2005
Posts: 194

Make sure you hava all the jars available in your lib folder

Abhish Sharma

Joined: Nov 14, 2011
Posts: 13
Where you are declaring your bean "SessionFactory" there is a space while defining the class make sure you spell word correctly.
I agree. Here's the link:
subject: Error creating bean with name 'sessionFactory'