Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play & Ebean - get first record

How is it possible to get the first record of a table in my database using the play.db.ebean.Model.Finder, like a "first" method. The corresponding SQL would be:

SELECT * FROM my_table LIMIT 1;
like image 667
alainschaller Avatar asked Dec 09 '22 05:12

alainschaller


1 Answers

Let's assume model Student

@Entity
public class Student{

@Id
public int id;

public String name;
}

Model finder will be

public static Finder<Long,Student> find = new Finder(Long.class, Student.class);

Retrieve Student limit by 1

public static Student getStudent()
{
    // Use setMaxRows(limit_by)
    return find.setMaxRows(1).findUnique();
}
like image 70
Sivakumar Avatar answered Dec 15 '22 15:12

Sivakumar