0

I have the following entities:

@Entity
@Table(name = "monthly")
public class MonthlySetting {

    @Id
    @Column(name = "id")
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "setting")
    private Setting setting;

}

@Entity
@Table(name = "setting")
public class Setting {

    @Id
    @Column(name = "id")
    private String id;

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(
            name = "recipient",
            joinColumns = @JoinColumn(name = "setting"),
            inverseJoinColumns = @JoinColumn(name = "recipient"))
    private List<Recipient> recipients;

}

@Entity
@Table(name = "recipient")
public class Recipient {

    @Id
    @Column(name = "id")
    private String id;

    @ManyToMany(fetch = FetchType.LAZY, mappedBy = "recipients")
    private List<Setting> settings;

}

And I'd like to create a Specification to select all MonthlySetting for which setting.recipients.id matches a given id. So far I've tried:

(root, query, cb) -> cb.like(root.get("setting").get("recipients").get("id"), "%" + id + "%");

But this throws the following error:

org.springframework.dao.InvalidDataAccessApiUsageException: Illegal attempt to dereference path source [null.setting.recipients] of basic type; nested exception is java.lang.IllegalStateException: Illegal attempt to dereference path source [null.setting.recipients] of basic type

I've seen this similar question, but the solution does not solve my problem (or I can't make it work)

thmasker
  • 406
  • 1
  • 9
  • 21

0 Answers0