I have a SpringBoot 2.6.11 application with JPA 2.2.
I have an entity like this:
@Data
@Entity
@Table(name = "entity")
public class Entity implements Serializable {
....
@Convert(converter = ListConverter.class)
private List<String> referenceCode;
....
}
I have this Converter:
@Converter(autoApply = true)
public class ListConverter implements AttributeConverter<List<String>, String> {
@Override
public String convertToDatabaseColumn(List<String> attribute) {
return String.join(";", attribute);
}
@Override
public List<String> convertToEntityAttribute(String dbData) {
return new ArrayList<>(Arrays.asList(dbData.split(";")));
}
}
And when I insert or extract this element all working fine. But now I wanna query that element and I don't know how to do it. If I do something like that:
public List<Entity> findByReferenceCode(String reference);
It doesn't work, if I do:
@Query("select e from Entity e where e.referenceCode IN ?1")
public List<Entity> findByReferenceCode(List<String> reference);
Still doesn't work..
The only way I found is by the nativeQuery but is really an extrema ratio. Ho can I solve this? Thank you