I have Entity called MyEntity
, one of the fields is List ids;
I'm storing it in database as separated coma values, like 1,2,3
thanks to
@Convert(converter = StringListConverter.class)
private List<String> ids = new ArrayList<>();
I want to retrieve MyEntity
from database specific id in mentioned list. Let's say number 1
. I did something like this below. Just for testing.
List<MyEntity> al = trainingPlanRepository.findAll();
List<MyEntity> as = al.stream().filter(me -> me.getIds().contains("1")).collect(Collectors.toList());
I would prefer to create custom query to get that but because of the conversion I can not handle it. (miss match type).
When I'm using db tool to handle my tables, below query works fine to achieve that, but it won't work as a custom jpa @Query.
select * from my_entity where ids like '%1%';