You don't need to write more (not sure where you get that idea). How to implement plain hibernate api based dao's is explained in the spring reference guide.
The HibernateTemplate isn't needed anymore since hibernate 3.0.1, since that release it became easier to plugin nicely to hibernate, before that spring needed some trickery, proxing and hackery to manage transactions, thread bound sessions and exception translation. Now with the newer versions of hibernate that isn't needed anymore, you still get all the nice stuff exception translation, session management etc. but without using any spring specific classes. Which imho is really nice it makes the use of spring even less obtrusive.
The code you posted would be more like
Code:
private SessionFactory sessionFactory;
@Autowired
public void setSessionFactory(final SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
@Override
@Transactional(readOnly = false)
public void saveUser(final User user) {
sessionFactory.getCurrentSession().saveOrUpdate(user);
}
@Override
@Transactional(readOnly = true)
public User getUser(final String email) {
final String query = "from User where email=:email";
Query query = sessionFactory.getCurrentSession().createQuery(query);
query.setParameter("email", email);
List<User> results = query.list();
if (!results.isEmpty()) {
return results.get(0);
}
return null;
}
If fixed your getUser method because that was flawed. NEVER NEVER NEVER (did I make myself clear) use string contact to include parameters into your query ALWAYS use placeholders, unless you want to be vulnerable to sql injection attacks! ALso you didn't check for any result which could potentially lead to exceptions.