Do anyone know how to construct these two SQL statement in HQL;
SELECT MIN(id) FROM Books WHERE mid < ? OR mid =?
SELECT SUM(noOfBooks) FROM Bookcount WHERE mId=128
Do anyone know how to construct these two SQL statement in HQL;
SELECT MIN(id) FROM Books WHERE mid < ? OR mid =?
SELECT SUM(noOfBooks) FROM Bookcount WHERE mId=128
They should work in HQL just fine. If you provide more details about the troubles you experience maybe we can help further.
Query q = session.createQuery("SELECT SUM(noOfBooks) FROM Bookcount WHERE mId=128");
Long result = (Long) q.uniqueResult();
And btw mid < ? OR mid =?
can be rewritten just like mid <= ?
You need to replace the sql columns with their HQL object mappings as specified in your hibernate mapping file. For example,
select min(b.id) from Book b where b.mId = 123
and
select sum(bc.numberOfBooks) from BookCount bc where bc.mId = 123