0
votes

I have a project, and his DAO classes extends HibernateDaoSupport, like this:

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;


public class SomeThingDAOImpl extends HibernateDaoSupport implements SomeThingDAO{

//methods here

}

Now, i have made the upgrade of that project, to use spring-boot and i'm using spring-data-jpa, for some reasons. But the problem is, the DAO classes are not in the Spring Application context and one exception occurs, like this:

Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required

The session factory, are automatically setted up when you implements JpaRepository interface using spring data, but i can't do that, cause the project needs somethings of HibernateDaoSupport, like getSession().createSQLQuery and other things.

Here are somethings that i already have made to pass by that exceptions:

  1. I've made the insertion of @Repository, to that class turn into a spring bean and be scanned by application context. don't work;

The question is: How can i start my application whithout that exception and make the session factory be initiated?

Edit 1: Here are some other parts of the code:

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;


public class SomeThingDAOImpl extends HibernateDaoSupport implements SomeThingDAO{



private static final String SQL_SELECT =
            "select ............";



@Override
    public User user(String name, String adress) {
        User result = new User();
        result.setName(name);
        result.setAdress(adress);
        SQLQuery query = getSession().createSQLQuery(SQL_SELECT)
                .addScalar("name", Hibernate.INTEGER)
                .addScalar("adress", Hibernate.STRING)         
        query.setString("name", name);
        query.setString("adress", adress);


return result;


}
1
Please share a more reproducible piece of code that can help us understand better and help you. - Suman
Go all in with Spring Data JPA. Convert all your SQLQueries to native queries. - Robert Niestroj
Can't do that, it's a extreme large project - Baptista

1 Answers

0
votes

After some research, a can't find a definitive solution to this, but i've made some changes in project and all are working now.

I've made the adition of @ImportResource({"classpath:applicationContext.xml"}) anotation, now i've two context configurarion files.