I tried to integrate
Spring 3 with
Hibernate 4 and I found that Spring don't support HibernateDaoSupport and HibernateTemplate any more in Spring's
Hibernate4 package.I have to use native Hibernate Session API.
So,here is my problem:
How can I findByExample(Object instance)(this is one method provided
by HibernateTemplate before) easily?
I have to splice sql by myself which is very painful.I have used mybatis before whose dynamic sql is very useful but I still don't think it is as easily as HibernateTemplate.
Hibernate itself have this funcionality, using the Example criterion. As you already have to use Hibernate's Session you could just do something like this:
List results = session.createCriteria(MyClass.class) .add( Example.create(object) ) .list();
More info on Hibernate Documentation.
I would suggest you to take a look at Spring Data JPA Repository.
Try with Spring data, another alternative could be write an generic dao class and injects the hibernate session on it.