I know this is simple question but taking more time
How to find first record from table in grails .
I need to get only the first record with out knowing the id number .
Is there any method like find :first in grails ?
thanks in advance .
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, you have to define by what measure this record is supposed to be the “first”.
Assuming that you mean the record with the earliest creation timestamp, the easiest and most robust approach would be to add a
dateCreatedproperty to your domain class and then querying for the entity with the lowest such date. In fact you don’t even have to set the creation date manually, because Grails does this for you (as long as you name the propertydateCreated) – see Automatic timestamping in the Grails Documentation.The HQL query would be something like: