Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In request there is first() but no last() #20

Open
Levvy055 opened this issue Nov 25, 2016 · 5 comments
Open

In request there is first() but no last() #20

Levvy055 opened this issue Nov 25, 2016 · 5 comments
Assignees

Comments

@Levvy055
Copy link
Collaborator

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 ?

@v-ladynev
Copy link
Owner

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.

@Levvy055
Copy link
Collaborator Author

Levvy055 commented Dec 5, 2016

So maybe better make method that will call SQL for first and last?

@v-ladynev
Copy link
Owner

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().

@Levvy055
Copy link
Collaborator Author

Levvy055 commented Dec 9, 2016

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

@v-ladynev
Copy link
Owner

Did you mean, that we should use something like CollectionUtils.last() for this last() method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants