Is there a way to override the findAll query executed by Spring Data Rest?
I need a way of filtering the results based on some specific criteria and it seems that using a @NamedQuery
should be along the lines of what I'm looking for so I setup a test.
@Entity
@Table(name = "users")
@NamedQueries({
@NamedQuery(name = "User.findAll", query="SELECT u FROM User u WHERE u.username = 'test'"),
@NamedQuery(name = "User.findNameEqualsTest", query="SELECT u FROM User u WHERE u.username = 'test'")
})
public class User implements Serializable, Identifiable<Long> { }
With this in place I would expect SDR to utilize my findAll() query (returning 1 result) but instead it executes the same old findAll logic (returning all results).
In my Repository I added:
@Repository
@RestResource(path = "users", rel = "users")
public interface UserJpaRepository extends JpaRepository<User, Long> {
public Page<User> findNameEqualsTest(Pageable pageable);
}
and in this case it DOES pick up the provided @NamedQuery
. So...
How should I go about overriding the default findAll()
logic? I need to actually construct a complex set of criteria and apply it to the result set.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…