Open Levvy055 opened 8 years ago
Yes, I can. But this last()
method will work the same way, as the first()
method does. Load all list in the memory and get the last element. It can be convenient, of course, but not more optimal than get a whole list.
So maybe better make method that will call SQL for first and last?
To use SQL to getting the last record, we need to use the DESC
order and get the first one. So the first()
method is enough in this situation. The first()
method was designing as a convenience method, for situation when we know that we need only one record, but Hibernate always returns a list (uniqueResult()
throws an exception for multiple records). We can just extend the first()
method to get only one record from a database using setMaxResults()
and uniqueResult()
.
I see that first() uses CollectionUtils which returns first element so let's for now do last Method there that like you said returns last element
Did you mean, that we should use something like CollectionUtils.last()
for this last()
method?
There is implementation of: H.request(MyClass.class).first(); but no: H.request(MyClass.class).last(); I need to make list() call than get last element, but the rest is not needed and takes unnecesary memory banks. Can you implement it in HibernateRequest ?