Reputation: 999
I have not much practiced Criteria and even less with the use of Spring classes such as HibernateDaoSupport.
I have inherited of a project where all Dao extend HibernateDaoSupport, and all methods are using Criteria by this way :
final Criteria criteria = this.getSession().createCriteria(MyClass.class, "alias");
Since I migrated the project under Maven and upgraded the Spring version (3.0.4 -> 3.2.17), getSession is deprecated.
What is the best practice to refactore all Criteria creation ?
Thank you.
PS: made some research, not found a real solution for moment...so forgive me if it's a duplicated subject or if there is a trivial answer
Upvotes: 2
Views: 5430
Reputation: 999
In practice, using the SessionFactory directly is good practice.
After research, this comes from the fact that in Spring 3, transaction management is now "optimal". But, unfortunately, in this inherited project the Spring configuration (1.x) is horrible and it is not possible to use the SessionFactory without refactoring.
In the end, we opted for the HibernateTemplate instead of HibernateDaoSupport. Its getSession method for creating Criteria is not deprecated.
Upvotes: 2