No HibernateUtil:
Funciona para todas as queries, porém, pode haver perda de performance.
public static Session getSession() {
if (SESSION_THREAD.get() == null) {
Session session = factory.openSession();
session.createSQLQuery("alter session set nls_comp=linguistic").executeUpdate();
session.createSQLQuery("alter session set nls_sort=binary_ai").executeUpdate();
SESSION_THREAD.set(session);
}
return (Session) SESSION_THREAD.get();
}
Diretamente no método de pesquisa:
public List<ContaPagar> findContaPagar(String campoPesquisa, String valor,Integer startRow, Integer MaxRows) {
List<ContaPagar> list = new ArrayList<ContaPagar>();
try{
session.createSQLQuery("alter session set nls_comp=linguistic").executeUpdate();
session.createSQLQuery("alter session set nls_sort=binary_ai").executeUpdate();
session.createSQLQuery("alter session set nls_sort=binary_ai").executeUpdate();
Criteria c = session.createCriteria(ContaPagar.class,"contaPagar");
c.createAlias("contaPagar.historicoFinanceiro", "historico",JoinType.LEFT_OUTER_JOIN);
c.setCacheable(true);
c.setMaxResults(MaxRows);
c.setFirstResult(startRow);
c.add(Restrictions.eq(campoPesquisa, StringToObject.toObject(valor)));
list = c.list();
}catch (Exception e) {
e.printStackTrace();
}
return list;
}
Nenhum comentário:
Postar um comentário