0

I worked on Spring Data JPA, it is amazing library, but you should write your Database finders as a method signature before you can use.

When I looked at Grails, I find the concept of I do not have to write method signature to use the finder, it has Dynamic finders

What kind of finders (static/dynamic) does Play Framework use?

Muhammad Hewedy
  • 29,102
  • 44
  • 127
  • 219

1 Answers1

2

According to grails definition of dynamic finders you can say that play framework finders are also defined in a dynamic fashion by using dot notation with the finder object. So a query such as:

SELECT * FROM PERSON WHERE name = 'Fred'

Would be created like so

public class Person extends Model {
    public Integer id;
    public String name;

    public static Finder<Integer,Person> find = new Finder<Integer,Person>(
                    Integer.class, Person.class); 
}

and you would write your dot-notation query where-ever like

List<Person> people = Person.find.where.eq("name", "Fred").findList();

Alternatively you can make the Finder object private and then write methods within the Person class which have method signatures defining the query such as:

public static List<Person> findByName(String name) {
    return find.where().eq("name", name).findList();
}

I find that writing all of the dot-notation queries within methods of the class to be more maintainable especially if you are working with a larger code base.

You can read a little more about it here

  • +1, but I cannot accept your answer as I see some thing like `Book.findByLastName` is different from writting some finder property and then use a syntax like `Person.find.where.eq("name", "Fred").findList()` – Muhammad Hewedy Aug 19 '15 at 09:56
  • BTW, I start looking at Slick http://slick.typesafe.com/doc/3.0.2/introduction.html#functional-relational-mapping, and I find it looks promising – Muhammad Hewedy Aug 19 '15 at 09:58