sunilkumarsh wrote:
Thanks a lot for answering my earlier question.
I tried it and its working.....
It will be nice of u ...
if u could make one more thing clear to me ....
Is it oky to use HQL?
If yes which situation should we use it ?
or we should always try and fetch objects using traversing ?
which of the 2 ways is efficient ?
whats the advantage of using either of them ?
In a majority of cases, you shouldn't need to use HQL but there are definitely cases where it comes in handy.
Check out section 14 Tips and Tricks of the documentation. I use HQL to check if a certain data exists in the database without having to return the data
Code:
select count(*) from Employee emp where emp.lastName = :lastName and emp.firstName = :firstName
Also anytime I need to use a subselect for example:
Code:
from MyObject myo where myo.dateCollected =
(select max(myo2.dateCollected)
from MyObject myo2 where myo2.id = myo.id)