Instead of specifying the field of an object that I want to search by in spring data, I want it to search by all of the fields. E.g.:
@Entity
@Table(name="FOO")
public class Foo{
private String firstName;
private String lastName;
private String middleName;
private String ssn;}
@Repository
public interface FooDao extends CrudRepository<Foo, Long>{
Foo findByFoo(Foo foo);}
Essentially what this does is look at the fields that are not null in a passed foo object and queries by them OR it queries all the fields the way they are, which can be null or not null.
Assume that Foo
has a lot of fields and trying to write individual queries wouldn't be very elegant.
I also understand that I can dynamically do this myself, but I'd rather not do that if it's already possible.
findByExample
mechanism. I have a sample application that you can look at for creating your own JPA repository implementation that provides afindByExample
of its own.