Languages
 
 
 
 
Follow Me



 
 

Hibernate. Count queries without HQL

  Tagged

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.

I have found new API method that can be used to create 'count' queries with Criteria class:

	public Integer countAddLogs(Long minLogID) {
		Criteria criteria = session.createCriteria(LogAdd.class);
		criteria.add(Restrictions.gt("id", minLogID));
		criteria.setProjection(Projections.rowCount());
		return (Integer) criteria.list().get(0);
	}

Look at Projections.rowCount(). This is what I'm talking about.

Maybe this is not a new and you are already familiar with this method, but I still decided to write short note about it.

Share this

burberry storesDecrease Constraint the least

Make sure you check out this article once. There is also another chair at IKEA that is slightly more expensive called the Gulliver. It was a rough few years cheap burberry, as I was determined to prove my worth by means of some capacity at another kind of game. If it is out in the elements get a cover, if you live in a very humid area, rust will eventually get it so you may want to spend a little more money more to combat that factor. One particular of the most common regrets movers have is hiring a shifting firm that leaves their points outside, forcing the freshly moved-in couple to lug sofas up three floors on their personal.For much more details burberry womens coats, you really should visit: . The best thing to do is identify a few perfumes that you think may work for you. It's usually given its name to a person's friends and neighbors; the girl has been remaining trained remaining sugary plus stylish, plus continually approachable. Low-priced liquor often leads to bad things. Another great option to consider as well when buying golf balls for practice is buying recycled balls or used ones. Spa fragrance can be exotic and spicy, floral, fruity, or tropical there are many options to give you the type of aromatherapy you need for your spa experience. The pants are generally created and stitched in a way that allows for easier bending in the knee burberry coat sale, making it convenient to be in the positions which the work needs. The company may face further shortage in supply of their chips during coming season due to current holdup scenario otherwise.. HornTrader has many great trumpets, including a part of the Malcolm McNabb trumpet collection and a large collection of New York Bach Stradivarius's, many of which are very rare and collectible. you should also purchase a wire guard to cover any exposed wires and cords that may trail out from the TV. If you are looking for a guitar amp that will produce some incredible sound quality, then this is the one for you.. Generally green tea is consumed vide steeping the leaves of the tea infused with warm water. This process requires less energy and its greater efficiency results in a light that is much brighter and more evenly distributed than a standard flashlight allowing the beam to be seen much greater distances. The lyrics are as follows: Baby, I've got plans tonight. Many UK hampers are purchased on a payment scheme over the year and then used for the Xmas period, helping individuals afford the cost of the loved Xmas treats desired over the holiday season. Loads of controls are equipped with dimmers for ceiling fans that include lights.Related articles:

Post new comment

CAPTCHA
Are You Human/Bot?
 
© 2006-2010 kobyleha.com