Override @Where clause condition in Hibernate 4.3.4
I know its too old question but I was facing same issue and thought I should share my workaround.
Totally agree with @cнŝdk answer as you cannot override but you can ignore @Where
clause by defining nativeQuery
as below:
@Query(value = "Select * from customer where company_id = ?1", nativeQuery = true) List<Customer> findByCompanyIdIgnoringEntityWhere(Long companyId);
The SQL in the @Query annotation must point the table's name and the fields' names (not entity's name).
AFAIK you can't override it inside your class because if you take a look at the @Where documentation you will see that this interface is annotated @Retention(value=RUNTIME)
so it has RUNTIME
as a RetentionPolicy
and you can see in the RetentionPolicy documentation that:
RUNTIME: Annotations are to be recorded in the class file by the compiler and retained by the VM at run time, so they may be read reflectively.
Which force the @Where
annotation to be recorded in the class file by the compiler and retained by the VM at run time, so it will be applied all over this class.