wood burning stoves 2.0*
The moose likes Spring and the fly likes integration with hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "integration with hibernate" Watch "integration with hibernate" New topic
Author

integration with hibernate

krunal prajapati
Greenhorn

Joined: Apr 18, 2011
Posts: 19

hello,

I have integrate spring with hibernate but i got error and i cant sovle it,


my file structure is following,




and my xml files are following,



2. spring-hibernate.xml


my java file is
1. springhibernatetest.java


2. employeedao.java



3. employee.java


and i got following error,

run:
Jul 8, 2011 3:56:50 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from file [C:\Documents and Settings\Administrator\My Documents\NetBeansProjects\SpringHibernate\src\resources\spring-hibernate.xml]
file [C:\Documents and Settings\Administrator\My Documents\NetBeansProjects\SpringHibernate\src\resources\spring-hibernate.xml]
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeDao' defined in file [C:\Documents and Settings\Administrator\My Documents\NetBeansProjects\SpringHibernate\src\resources\spring-hibernate.xml]: Cannot resolve reference to bean 'hibernateTemplate' while setting bean property 'hibernateTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateTemplate' defined in file [C:\Documents and Settings\Administrator\My Documents\NetBeansProjects\SpringHibernate\src\resources\spring-hibernate.xml]: Cannot resolve reference to bean 'mySessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'mySessionFactory' is defined
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1317)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1076)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at com.spring.hibernate.SpringHibernateTest.main(SpringHibernateTest.java:26)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateTemplate' defined in file [C:\Documents and Settings\Administrator\My Documents\NetBeansProjects\SpringHibernate\src\resources\spring-hibernate.xml]: Cannot resolve reference to bean 'mySessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'mySessionFactory' is defined
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1317)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1076)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
... 10 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'mySessionFactory' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:510)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1056)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:274)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
... 20 more
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)


thanks in advance,
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507


where is mySessionFactory defined? you have to change it to SessionFactory or change that bean id to mySessionFactory.


Regards, Prasad
SCJP 5 (93%)
N Sahni
Ranch Hand

Joined: Jul 07, 2011
Posts: 55

The exception itself says that Cannot resolve reference to bean 'mySessionFactory' while setting bean

In spring-hibernate.xml you should either make <ref bean="SessionFactory" /> or rename the bean id for declaring session factory like: <bean id="mySessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

PS: In spring make sure that the bean you are referring to is declared properly.


Thanks and Regards,
Nilesh Sahni | nsahni@infocepts.com | www.infocepts.com
krunal prajapati
Greenhorn

Joined: Apr 18, 2011
Posts: 19

but I have problem in creating bean with name 'employeeDao'.

please refer error in bold.



run:
Jul 9, 2011 10:29:08 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from file [D:\Documents and Settings\KRUNAL\My Documents\NetBeansProjects\SpringHibernate\src\resources\spring-hibernate.xml]
file [D:\Documents and Settings\KRUNAL\My Documents\NetBeansProjects\SpringHibernate\src\resources\spring-hibernate.xml]
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeDao' defined in file [D:\Documents and Settings\KRUNAL\My Documents\NetBeansProjects\SpringHibernate\src\resources\spring-hibernate.xml]: Cannot resolve reference to bean 'hibernateTemplate' while setting bean property 'hibernateTemplate'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'hibernateTemplate' is defined
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1317)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1076)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at com.spring.hibernate.SpringHibernateTest.main(SpringHibernateTest.java:26)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'hibernateTemplate' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:510)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1056)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:274)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
... 10 more
Java Result: 1
BUILD SUCCESSFUL (total time: 5 seconds)
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Whenever you get an exception from Spring, always scroll to the bottom of the stacktrace and read up till you get to the first "Caused By" from the bottom, that is always your root exception and problem. In this case, it can't find a bean named "hibernateTemplate"

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
krunal prajapati
Greenhorn

Joined: Apr 18, 2011
Posts: 19

thank you for suggestion,
I had problem with bean id naming and now it has been solved....


thank you again to both of you sir.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

krunal prajapati wrote:thank you for suggestion,
I had problem with bean id naming and now it has been solved....


thank you again to both of you sir.


Fantastic.

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: integration with hibernate
 
Similar Threads
Spring+Hibernate can't create SessionFactory bean
problem while integrating spring with hibernate in webapplicatin development
Exception in thread "main" org.springframework.beans.factory.BeanCreationException
getting error
Caused by: org.hibernate.HibernateException: could not instantiate CacheProvider: ...please help me