I'm trying to make a query to search all Posts from my application containing a keyword on the content or on the tags name but only those who are public. I'm trying to make the JPQL search but I don't know how to access the tags.name property.
Note: Post
is an entity which has a List of Tag
entity;
I have tried this but it's not working (as I expected):
@Query("SELECT p FROM Post p WHERE (p.content LIKE CONCAT('%', LOWER(:keyword),'%' OR p.tags.name LIKE CONCAT('%', LOWER(:keyword)) AND (p.open IS TRUE)")
I have looked at the documentation but I don't see any option to manage this, what is the best way to go here?
Thanks!
Since multiple
tag
s can be associated with apost
the relationship is a@OneToMany
fromPost
toTag
. Ajoin
should work in this scenario.Try this.
PS : I have not tested this, but it should work.