From the course: Java Database Access with Hibernate
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Aggregate methods - Java Tutorial
From the course: Java Database Access with Hibernate
Aggregate methods
- [Instructor] In addition to using name parameters, we also have access to some aggregate methods. These are similar to what you might see in Excel. We can find the average, the count, the count distinct, max and min, and the sum. Let's try an example. Let's do an hql example that finds the max salary of all the employees. I'm going to go ahead and change my string, hql, to say, this time instead of from employee, I'm going to take that out, I'm going to say select the max, and I want to use the salary. Going to do e.salary from the Employee table using the alias as e. Next, I'm going to leave my query and createQuery the same, and I don't have any named parameters, so I'm going to delete line 50, but instead of getting a list, I'm only going to get one value. Let's create an integer. I'll do int s is equal to, and I'm actually going to do an int, and I'm going to say query.uniqueResult, 'cause I'm only going to get one value for the max. Now, I can just go ahead and print out the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.