tags:

views:

55

answers:

2

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
A: 

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 <= ?

serg
A: 

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
Kartik
This also does the trick too! cheers.