0

I have dozen of Spring Data JPA repositories mostly creating queries based on the query method names, but also manually created using @Query. Now I would like to add an additional where condition e.g. owner = <USER> where USER is dynamically provided in Runtime to all the existing queries.

Is there a way how this can be achieved in Spring Data?

Adam Siemion
  • 15,569
  • 7
  • 58
  • 92

1 Answers1

1

According to this response response you should add the Where annotation to the domain class where the repository is related.

@Entity
@Where(clause = "active='true'")
public class Customer {
    //...
    @Column
    private Boolean active;
}

Where clause link

cralfaro
  • 5,822
  • 3
  • 20
  • 30
  • I have closed my question too early and now I cannot reopen it - I need to be able to dynamically provide the where conditions (i've updated the question) – Adam Siemion Jan 08 '19 at 14:25
  • See Hibernate FIlter functionality which "*allows you to define a restriction clause similar to the existing "where" attribute available on the class and various collection elements. These filter conditions, however, can be parameterized. The application can then decide at runtime whether certain filters should be enabled and what their parameter values should be*" https://docs.jboss.org/hibernate/orm/3.6/reference/en-US/html/filters.html – Alan Hay Jan 08 '19 at 16:14