Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore Hibernate @Where annotation

Tags:

I have an Entity which has an association to another Entity annotated with @Where, like so

public class EntityA {      @OneToMany     @Where(...)     private List<EntityB> entityBList;  } 

Recently the inevitable has happened, I need to load EntityB's that don't conform to the @Where clause. I could remove the @Where annotation, but it is used a lot, so ideally I don't want to do that. Apart from loading the list of EntityB's manually, with another query, what are my options? Can I tell Hibernate to ignore the @Where annotation?

like image 503
Zecrates Avatar asked Feb 22 '10 13:02

Zecrates


1 Answers

I just had the same question. I solved the problem like this:

@Query(value="SELECT * FROM EntityA", nativeQuery=true) public ignoreWhereMethod(){} 

The SQL in the @Query annotation must point the table's name and the fields' names (not entity's name).

like image 101
Yuri Hassle Araújo Avatar answered Sep 28 '22 10:09

Yuri Hassle Araújo