Languages
 
 
 
 
Navigation
 
 
 
 
 
 

Archives

Date
  • Jan
  • Feb
  • Mar
  • Apr
  • May
  • Jun
  • Jul
  • Aug
  • Sep
  • Oct
  • Nov
  • Dec
  • 01
  • 02
  • 03
  • 04
  • 05
  • 06
  • 07
  • 08
  • 09
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

Hibernate. Count queries without HQL


I like to use Criteria class for making database queries. Its easy to use and easy to understand, much better then HQL queries. For example:

  @SuppressWarnings("unchecked")
  public List<LogAdd> findAddLogs(Long minLogID) {
    Criteria criteria = session.createCriteria(LogAdd.class);
    criteria.add(Restrictions.gt("id", minLogID));
    criteria.addOrder(Order.asc("date"));
    return criteria.list();
  }

Previously I had to use HQL only for writing 'count' type queries. Because just trying to get collection size mean to load all elements into memory from database and only then count them. Of course such kind of code isn't acceptable.


 
 
 
 
 
 
  • hooligan
  • cupuyc
  • ESoImk
  • LeKz
  • Anton
 
 
 
© 2006-2008 kobyleha.com