I'd like to convert this SQL Statement into either Criteria or Projections. I'm sorry I don't know which one to use since I'm new to Hibernate. I've done some research, and it looks like both are needed to achieve what I wanted.
Before I always use SQL Statements in my programs but when I saw a sample code which allows you to create queries without writing SQL Statements by using Criteria, I wanted to use it since it gives me cleaner code.
Thanks in advance.
String query = "SELECT MAX(employeeNo) "
+ "FROM Profile "
+ "WHERE SUBSTRING(employeeNo,1,2)='" + yy + "'";
empNo = session.createQuery(query).list().get(0).toString();
This query gets the highest employee number in the database for a given year yy
.
Sample result would be 14-229