Anthony Richir
Anthony Richir

Reputation: 649

Does Hibernate's @Where annotation works with Spring Data JPA?

As the title says, I'm trying to use Hibernate's @Where annotation with Spring Data JPA but without success, is it actually supposed to work together ?

Upvotes: 0

Views: 3734

Answers (2)

Stefan
Stefan

Reputation: 157

I tried to use @Where on a @OneToMany relation and I noticed that it only works when the entity is managed by Hibernate.

So when I created my entity and saved it through a Spring Data repository it doesn't worked (the collection was empty and there was no query in the log). But when I fetch the entity via the repository (using findById(...) or something) and I accessed the relation with the @Where annotation it did worked.

Maybe this is what you are experiencing as wel?

Upvotes: 0

Anthony Richir
Anthony Richir

Reputation: 649

While working on the example to demonstrate my problem, I realized what was wrong.

My problem is that the @Where annotation was set on an abstract parent class that we wanted to have for all our entities to extend and be able to soft deleted everything.

Unfortunately, it seems that, when set on a parent class, the @Where is not used (maybe on purpose and I'm not aware of it).

Here is my example which demonstrate that, when used on the entity directly, it's working, and when used on a parent class, it doesn't.

Example @Where Annotation

Upvotes: 2

Related Questions