try {
session = openSession();
String qString = "SELECT Transaction.id, Book.id, Book.title, max(Transaction.id) AS max_Transaction__id FROM Transaction RIGHT JOIN Book ON Book.id = Transaction.bookId GROUP BY Book.title";
// String qString = "SELECT Transaction.id, Book.id, Book.title FROM Transaction RIGHT JOIN Book ON Book.id = Transaction.bookId";
SQLQuery query = session.createSQLQuery(qString, true);
query.addScalar("Book.id", Type.LONG);
query.addScalar("Transaction.id", Type.LONG);
query.addScalar("Book.title", Type.STRING);
query.addScalar("max_Transaction__id", Type.LONG);
System.out.println(qString);