If I have an entity with this structure:
@Entity
public class RecipeRaw {
@Id
@GeneratedValue
Long id;
@ElementCollection
List<String> listOfIngredients=new LinkedList<String>();
and I want to get a list containing all ingredients that contains the word X in it. How to do that?
for example if the word is beef, I want to get a list of ingredients like 'ground beef' , 'dried beef with salt' and so on.
I tried
@Query("select ings_temp from
(select rr.listOfIngredients ings_temp from RecipeRaw rr) ings
where ings LIKE '?1'")
But this throws an error. Is there any simple way to do this query?
I solved it by this
@Query("SELECT DISTINCT t FROM RecipeRaw rr JOIN rr.listOfIngredients t "
+ "WHERE t LIKE CONCAT('%', :ing_name, '%')")
List<String> findIngredientsByLikeName(@Param("ing_name") String name);
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