Hello all,
i was an application that in Dao implementations with Spring framework:
like the spring samples, works well. I begin a new application and now the Dao i'm going to implement it with Hibernate.Code:public class UsersDaoImpl extends JdbcDaoSupport implements UsersDaoDao { /** Holds users Query Object. */ private UsersQuery usersQuery; ... protected void initDao() throws ApplicationContextException { if (usersQuery == null) usersQuery = new UsersQuery(getDataSource()); ... } ... protected static class UsersQuery extends Query { protected UsersQuery(DataSource ds) { super(ds, new StringBuffer().append("SELECT ... ").toString()); compile(); } } ... }
I thought that i had to do the same, save the Query like a attribute:
well, it don't work. i thought that was better create the Queries once because performance.Code:import net.sf.hibernate.Query; ... public class UsersDaoImpl implements UsersDaoDao { private SessionFactory sessionFactory; /** Holds user Query Object. */ private Query usersQuery; ... protected void initDao() throws ApplicationContextException { if(sessionFactory == null) { throw new ApplicationContextException("Must set hibernate..."); } this.createUsersQuery(); ... } ... private void createUsersQuery() { Session session = SessionFactoryUtils.getSession(sessionFactory, true); try { StringBuffer select = new StringBuffer(); select.append("from users in class domain.User"); this.usersQuery = session.createQuery( select.toString() ); } catch (HibernateException ex) { throw SessionFactoryUtils.convertHibernateAccessException(ex); } } ... public List findAllUsers() throws DataAccessException { List listUsers = null; try { listUsers = this.usersQuery.list(); return listUsers; } catch (HibernateException ex) { throw SessionFactoryUtils.convertHibernateAccessException(ex); } } }
when i insert a new user, the Query return the same List.
how do it this???
thanks in advance,
César.


Reply With Quote