Home > Back-end >  Parameter value did not match expected type java.util.Set
Parameter value did not match expected type java.util.Set

Time:03-11

I have the following entity:

@Entity
public class Person extends BaseEntity {
    private static final String PETS_SEPARATOR = ";";

    @Id
    @Nonnull
    private String id;

    @Column(name = "pets")
    @Convert(converter = StringSetConverter.class)
    @Nonnull
    private Set<String> pets;
}

And the StringSetConverter basically parses between String (separated by ;) and Set.

Notice that this is inherited code and I cannot easily change the database structure to have the pet relations in a separated table.

This causes having in the database a string like: "DOG;CAT;BIRD". And I want to find all the users that have "CAT", for instance.

So I tried a silly search like this one

Specification<UserEntity> petsSpecification = 
    (root, criteriaQuery, cb) -> {
        return cb.like(root.get("pets"), "           
  • Related