Reputation: 2084
I'm developping an application using spring and hibernate.
When I run my application I get this error message:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'transactionManager' is defined
In my context application file I have this :
<bean id="tansactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
I googled about the problem and I found a solution that I have to change this line :
<bean id="tansactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
By :
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
But I got another problem :
org.springframework.beans.NotWritablePropertyException: Invalid property 'sessionFactory' of bean class [org.springframework.orm.jpa.JpaTransactionManager]: Bean property 'sessionFactory' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
How can I solve this problem ?
Upvotes: 2
Views: 6411
Reputation: 21
You have a typo in your annotation "tansactionManager" is missing and 'r', "transactionManager". I made the correction and it worked just fine for me.
Upvotes: 2
Reputation: 176
If you are using session factory, so this should work
<bean id="tansactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
but if you want to use JPA EntityManager, so you need
<bean name="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
Please refer to migrating-to-spring-3-1-and-hibernate-4-1 it contains nice example for the required configurations
Upvotes: 1