Lets imagine that I have some Product entity with java.List of tags, as blelow:
@Entity
public class Product impements Serializable{
...
private List<String> tags;
}
and I have user, that wants to search for products tagged (for example) by any of tags: Car, Motocycle, Plane.
so when it comes to search i have list of tags in my entity, and list of search tags, where all i need is to have at least one of them it in my product's tags list. I don't know how to write such query. thx for help
before beny23 posted his solution i fixed it by adding
SELECT p FROM Product p, IN (p.tags) t where t in (:searchList)
but his answer is also correct.
You can do this using the following HQL query:
session.createQuery("from Product p join p.tags t where t = :tag")
.setString("tag", tagToSearchFor)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With