Related: Trouble Shooting
ebeaninitcommand line tool to generate Finders for us.
We can create and use a Finder for each of our entity beans, for example a CustomerFinder for the Customer entity bean. We do this to organise our code grouping all the "finder logic" for a given bean type into it's finder (so that everyone knows where it is).
A CustomerFinder generated by the
ebeaninit command line tool.
package org.example.domain.finder import io.ebean.Finder import org.example.domain.Customer open class CustomerFinder : Finder<Long, Customer>(Customer::class.java)
When we generate Finders these are also linked to the entity via a public field.
We can use
ebean-mocker when we want to mock or stub the finders for
With Kotlin we have the finder as a
... @Entity class Customer( ... companion object Find : CustomerFinder() }
Example Finder use
With the CustomerFinder linked as a field to Customer we can then easily use it.
// find by id val customer = Customer.byId(1L) // reference val customerReference = Customer.ref(1L) val customers = Customer.query() .where() .istartsWith("name", "hello") .findList(); // generally it is recommended that we move "find logic" for Customer // into the CustomerFinder so instead we should create a "byName" method // on CustomerFinder and end up with: val customers = Customer.byName("hello");