0

Hii iam doing spring ORM with hibernate. while running the program iam getting bellow error.. iam giving all my config,pojo,daos please check

 WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vehicleDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.orm.hibernate3.HibernateTemplate in.JavaHome.SpringHiber.DAO.vehicleDao.template; nested exception is java.lang.NoClassDefFoundError: [Lorg/hibernate/engine/FilterDefinition;
Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.util.ReflectionUtils.clearCache()V
    at org.springframework.context.support.AbstractApplicationContext.resetCommonCaches(AbstractApplicationContext.java:879)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:563)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at addVehicle.main(addVehicle.java:11)

Configuration spring is..

<context:component-scan base-package="in.JavaHome.SpringHiber"></context:component-scan>

<bean name="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="configLocations" value="classpath:hibernate.cfg.xml"></property>
</bean>

<bean name="hibTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<bean name="hibTransManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<tx:annotation-driven transaction-manager="hibTransManager"/>

Dao Class

@Component
public class vehicleDao {

    @Autowired
    private HibernateTemplate template;

    @Transactional
    public void addVehicle(vehicle v){
        template.save(v);


    }

main.java

public static void main(String[] args) {
        // TODO Auto-generated method stub
        ApplicationContext contex= new ClassPathXmlApplicationContext("config.xml");
         vehicleDao dao = (vehicleDao) contex.getBean("vehicleDao.class");

         vehicle v=new vehicle();
         v.setName("S cross");
         v.setCost(1500000);

         dao.addVehicle(v);

    }

Iam new to spring mvc so, please tell me the whr the problem.

Thank u

2 Answers2

0

If my guess is correct, you are following a Tutorial to learn about Spring. If so, congratulations and good luck, Spring is a very powerful framework! Though it appears that you are using a very old tutorial - I'd suggest looking for a more modern spring tutorial example as XML configuration (as well as Hibernate 3) are not modern approach. Perhaps something from: http://spring.io/guides

but for this specific problem it seems likely that you have incompatible jars on your classpath. If you plan to use hibernate 3 you need to ensure it's on the classpath and that you are not using a modern version of spring either. See: compatability of spring 4.0.0 with hibernate 4.30

Community
  • 1
  • 1
Ben M
  • 1,833
  • 1
  • 15
  • 24
  • Thank you so much for the information. But i want to learn Spring ORM,Spring MVC, So, can you suggest any gitHub location – rajawin2008 Feb 03 '16 at 07:28
  • I'd suggest looking at Spring Data JPA and working through examples such as http://spring.io/guides/gs/accessing-data-jpa/ for ORM, and http://spring.io/guides/gs/serving-web-content/ or http://spring.io/guides/gs/rest-service/ for MVC (depending on if you are building a web page or services) – Ben M Feb 03 '16 at 07:39
-1

The problem is you defined bean in xml like this

<bean name="hibTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory"></property> </bean>

but your using template to autowire the bean name should be same or use @Qualifier

@Autowired
  private HibernateTemplate template;

change this to

@Autowired

private HibernateTemplate hibTemplate;

or

@Autowired @Qualifier("hibTemplate") private HibernateTemplate hibTemplate;