Issue
In my spring project I am using hibernate for access database..
I have
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
p:dataSource-ref="dataSource" p:packagesToScan-ref="packagesToScan"
p:hibernateProperties-ref="hibernateProperties" />
<util:map id="hibernateProperties">
<entry key="hibernate.show_sql" value="false" />
<!-- <entry key="hibernate.hbm2ddl.auto" value="update" /> -->
<entry key="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
</util:map>
<util:list id="packagesToScan">
<value>com.preeti.myproject</value>
</util:list>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory" />
In pom file I have:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.11.Final</version>
</dependency>
But when I run that project I am getting error:
Error creating bean with name 'SignupController':
Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field:
private com.preeti.myproject.service.UserService
com.preeti.myproject.controller.SignupController.userService
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'userService':
Injection of autowired dependencies failed;
Could not autowire field:
private org.hibernate.SessionFactory com.preeti.myproject.hibernate.AbstractHibernateDao.sessionFactory;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory' defined in ServletContext
resource [/WEB-INF/spring-servlet.xml]: Invocation of init method failed;
nested exception is java.lang.ClassCastException:
org.hibernate.annotations.common.reflection.java.JavaReflectionManager
cannot be cast to org.hibernate.annotations.common.reflection.MetadataProviderInjector
when I used
hibernate 3.5.0-final,
hibernate-core-3.5.4-Final,
hibernate-entitymanager-3.5.4-Final,
hibernate-commons-annotations-3.3.0.ga
that project has no error..
What I have to update to reduce this errors..
Solution
Go to project(right click)>properties>libraries
delete all jars.
you have pom.xml file that means you are using maven.
So,go to terminal >locate your project then run :
mvn clean install
Answered By - user3553286
Answer Checked By - Cary Denson (JavaFixing Admin)